Get to know these commands so you can give yourself a break and keep things simple when using git.
| Command | What does it do? |
|---|---|
git show-branch | compare the commits in 2 or more branches. Use this obsessively / compulsively |
git fetch | obtain all branches and changes from a remote(s) |
git rebase | reorder, rename, remove commits, sometimes to add commits from one branch into another |
git reset | set your active branch to a particular commit |
git reset --hard | set your active branch to a particular commit and wipe out any uncommitted changes (staged or unstaged) you have going locally |
git push | push code to a remote |
git push --force-with-lease | steamroll what’s on the remote (unless there’s something novel there you don’t have locally) |
git cherry-pick | grab a commit from anywhere and try to apply it to your current checked-out commit |
Git commands to avoid
Try to avoid these as much as possible.
| Command | What do? | When to use |
|---|---|---|
git pull | equivalent of (by default) git fetch && git merge <branch> | please don’t use this. Use git fetch and git rebase or git merge (if fast-forward) instead |
git merge | add commits from one branch into another using a (sometimes optional) “merge commit” | except for fast-forwards, use this as sparingly as possible. Use git rebase instead |
git push --force | steamroll what’s on the remote regardless of whether you have a record of it locally | only in very rare circumstances |
A note on GUI tooling
There are a number of graphical, point-and-click interfaces to Git. Until you are super comfortable with the command line interface, avoid these as much as you can. Once you’ve got the command line down pat and are able to do whatever you want with it, then see if you can get anything more from the GUI.