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-branch

Base it on an up-to-date main:

git switch main
git pull
git switch -c my-branch

Commit 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-branch

After 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/main

Switch between branches

git switch main                  # back to main
git switch -                     # to the previous branch
git branch                       # list local branches

See also