Skip to content

Instantly share code, notes, and snippets.

@verticalgrain
Last active May 27, 2019 20:48
Show Gist options
  • Save verticalgrain/d55856c38ed79f1de6329bfc0a800aaa to your computer and use it in GitHub Desktop.
Save verticalgrain/d55856c38ed79f1de6329bfc0a800aaa to your computer and use it in GitHub Desktop.
Git cheatsheet
// Checkout by hash:
git checkout 970327a74bce000242e08b0d6aeaa19ed03add7c
// To get back to normal branch:
git checkout master
// Git log only merges:
git log --merges
// Remove files from the tree
// First add the file name to .gitignore, then
git rm --cached <file-name>
// Directory:
git rm -r --cached directory/
// Undo a git pull or git merge before it's been committed or pushed
git reflog // Pick the hash of the commit you want to roll back to
git reset --hard c03fd373
// Undo a git add & git commit (before push)
git reset HEAD^\
// Check if any files have whitespace issues or merge conflict marks
git diff --check master
// Archive old merged branches, locally and remotely
git tag archive/mybranch mybranch
git branch -D mybranch
git push origin :mybranch
// Check what branches have NOT been merged into a certain branch (feature/whatever)
git branch --no-merged feature/whatever
// Git stash!
git stash // Stash the currently unstaged files
git stash list // list the stashes
git stash apply // apply the most recent stash
git stash apply stash@{2} // Apply a specific stash
git stash show -p | git apply -R // Unapply the most recent stash
git stash show -p stash@{0} | git apply -R // Unapply a specific stash
$ git config --global alias.stash-unapply '!git stash show -p | git apply -R' // Make an alias that does stash unapply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment