Merge upstream branch often
If your branch lives for more than a day or two, I prefer to merge the base branch into it regularly.
This is especially useful before you continue working on an existing branch.
Why?
- conflicts stay small
- test failures show up earlier
- merge conflicts later are smaller and easier to resolve
I usually do this while I am on my feature branch:
# Maybe someone else pushed to your branch. Get these change to your local directory
git pull
# Get changes from base branch. In most cases this is "main".
git merge origin/main
I use origin/main here instead of local main because local main might be outdated. A git fetch
updates origin/main, even if you have not switched to main or pulled it recently.