Branch Workflow
Everyday flow for doing work on a side branch and getting it back to the remote. Generic terms — swap in your own branch and remote names.
Start a side branch
git switch -c my-branch # create and switch to a new branch
# older git: git checkout -b my-branchBase it on an up-to-date main:
git switch main
git pull
git switch -c my-branchCommit work
git add <files> # stage specific files (safer than git add -A)
git commit -m "message"Push to the remote
First push of a new branch sets its upstream:
git push -u origin my-branchAfter that, just git push.
Keep the branch current with main
git fetch origin
git merge origin/main # merge main into your branch
# or, to replay your commits on top:
git rebase origin/mainSwitch between branches
git switch main # back to main
git switch - # to the previous branch
git branch # list local branchesSee also
- Resolve Divergent Branches — when a
git pullrefuses because local and remote have both moved. - Diagnose and Recover from Branch Collisions — when a rebase has already conflicted or a commit seems to have gone missing.