Git Cheat sheet

Abe Petrillo by Abe Petrillo on September 15, 2014

Git commands that I always forget but find useful:

# Recover a file:
git checkout <previous-commit-hash> <file_path>

# Ignore changes to certain files:
git update-index --assume-unchanged config/database.yml

# Take commit from another branch:
git cherry-pick <commit reference>

# Delete multiple branches starting with some string:
git branch -D `git for-each-ref --format="%(refname:short)" refs/heads/some_string\*`

# Delete all branches merged with master
git branch --merged | egrep -v '(^\*|master)' | xargs git branch -d

# List branches in order of which most recent commit
git for-each-ref --sort=-committerdate refs/heads/

I tend to alias things so when on another machine it’s handy!