Here's a (growing) collection of git commands/tricks that I find useful. While there are many more, these are ones that I use on a daily basis.
git checkout -: switch to the previous branch. Very similar to cd -
git checkout .: discard all unstaged changes. This action is irreversible.
git add -p: Interactively stage files. Similar experience to git rebase -i
gitignore <language>: This is a custom function you can add to your bashrc. Please refer to gitignore.io for more usage information.
gitignore() {
curl -L -s "https://www.gitignore.io/api/$1" >> .gitignore
}git reset HEAD~1: "un-commit" your last commit
git branch -m <original> <target>: move branch to new location. Useful if you misspell a branch name. Similar to mv. If you have already pushed the bad branch, run git push origin --delete <original> then git push origin <target>
git commit --amend: add changes to the previous commit. If changes have already been published, use git push -f to force push the changes to the remote origin.
git log --oneline: Single line git log.
git log --graph: log git history in graph form.