Skip to content

Instantly share code, notes, and snippets.

@geoffyuen
Last active February 19, 2021 21:32
Show Gist options
  • Save geoffyuen/ae4ce3aaddc86c70d2feda35ef2f2653 to your computer and use it in GitHub Desktop.
Save geoffyuen/ae4ce3aaddc86c70d2feda35ef2f2653 to your computer and use it in GitHub Desktop.
Git Cheatsheet

Git Cheatsheet

Just get the latest version

Good for skeleton themes, frameworks, etc

git clone --depth=1 <remote_repo_url>

Merge branch and continue:

git checkout master
git pull
git merge Farmcrops
git push origin master
git branch -d Farmcrops
git checkout master
git checkout -b Farmcrops

or

git checkout master
git pull
git checkout Farmcrops
git merge master
git checkout master
git merge Farmcrops

Pull master and overwrite local files

git fetch —all
git reset —hard origin/master

Branch current changes

git checkout -b newBranch

Delete Branch

git branch -d Farmcrops

File changes from 8 days ago

git log --pretty=format: --name-only --since="8 days ago" | sort | uniq

or prettier

git diff --stat @{8.days.ago}

the first way seems to show more file changes(?)

File changes from SHA to SHA

git diff --name-only SHA1 SHA2

List Remotes

git remote -v

Make changes to a file but don't track that change

Use this for things like gulpfile.js.

git update-index --assume-unchanged [<file> ...]

New branch with current uncommited files

git checkout -b newbranch
git add --all
git commit -m "your message"

Pull branch without switching (pull remote dev into local dev)

git pull origin dev:dev

Merge branch without switching (merge yourbranch into dev)

fetch . yourbranch:dev

Pull, merge push without switching

Alltogether now:

Assuming you are on yourbranch and you want to merge and push dev

git pull origin dev:dev
fetch . yourbranch:dev
git push origin dev
git merge dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment