Skip to content

Instantly share code, notes, and snippets.

@saltmade
Last active September 17, 2018 20:25
Show Gist options
  • Save saltmade/80f2605c4ff23cc0d2d3d582ffedb06f to your computer and use it in GitHub Desktop.
Save saltmade/80f2605c4ff23cc0d2d3d582ffedb06f to your computer and use it in GitHub Desktop.
A git cheatsheet

My Git Cheatsheet

A collection of git commands and also a method of recording my git knowledge

Add changes hunk by hunk (aka patch) git add -p

Edit previous commits git rebase -i <commit ID>

Add all untracked files to the index without adding content (good for use with patch) git add . --intent-to-add OR git add -N .

Fetch and merge remote changes as a rebase instead of on top git pull --rebase <remote name> <branch name>

Revert a single file to HEAD git checkout <filepath>

Delete already merged branches from master git remote prune origin git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

Show edits to a given file and search for a term, showing 10 lines before and after git log -p path/to/file.py | grep -C 10 'your search term'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment