A friendly cheatsheet that answers the questions I find myself asking embarrassingly often...
git fetch origin # update everything you're not working on
git diff master origin/master # see what's changed
git merge origin/master # update what you're working on
# ^ There might be merge conflicts to deal with...
NOTE: git pull conveniently wraps the above commands, but best to know what's going on.
git branch -r # r(emote) branches
git checkout --track origin/feature # now on branch 'feature'
git checkout -b difficult origin/feature # now on branch 'difficult'
Local branches are what you work on. But a local branch can and often will (confusingily) track a remote-tracking branch. Basically, the remote branch is not on your machine, so all you can really do with it is:
- Update from it with git fetch
- Merge from it into your current branch
- Create new local branches based on it
git checkout plzwork
git checkout -b hotfix plzwork
git checkout target # or master, or whatever
git merge --squash --ff-only # flags are optional, but good defaults
NOTE: with both merge and rebase you invoke them from the target branch.
That is, the branch you're merging to or the branch you're rebasing.
If you want to keep the merged branch going...
git checkout spinoff
git rebase target
Or if you're done with it.
git branch -d spinoff # d(elete)
git checkout -b hotfix
# ...commits n stuff
git push origin hotfix
# ...mange in the repo UI