Building on the tips and other points explained elsewhere, this workflow has the following advantages relative to always working on the master branch:
For the purposes of having an easy-to-remember label, I will refer to this workflow as the "No Switch Yard" (NoSY) workflow.
For each specific, well-defined task:
git checkout -b <local-branch>
git fetch origin; git rebase origin/master
git checkout master
git pull
git merge --ff-only <local-branch>If this operation fails:
git checkout <local-branch>
git rebase origin/master
git push
git branch -d <local-branch>
Imagine that you have been making some commits to your local repository on the master branch, and you realize (perhaps because your project is turning out to be a bit more involved than you thought, or because a slew of changes have just appeared upstream) that you might have been better using NoSY. It's actually quite easy to swap to using NoSY without any disruption to your already-committed changes. Starting from your current position on the master branch:
git stash
git branch <local-branch>
git fetch origin
origin/master
:git reset --hard origin/masterNote that you have not lost your local commits: they are on your local branch already.
git checkout <local-branch>
git rebase origin/master
git stash pop
Reproduced with permission from the following page: https://cdcvs.fnal.gov/redmine/projects/cet-is-public/wiki/GitTipsAndTricks#A-suggested-work-flow-for-distributed-projects-NoSY by