I'm quite new to Git and GitHub, so please help me with this question!
I want to contribute to a github project, so I did the following steps:
- I forked the original repository (the so called
upstream, right?) - I git cloned my fork locally (
git clone 'myforkrepo') - I created a new branch to work on a new feature (
git switch -c myfeatureA) - I also created a new branch from main to work on another separate feature (
git switch mainand thegit switch -c myfeatureB) - I was working on my local branches when I realised that, meanwhile, the upstream main was updated!
- I read about Syncing a fork - GitHub Docs and I added the original repo as upstream, switched to my local main and **merged **(
git merge upstream/main) (Or should I rebase?).
Now, my question is: since I need to update all my local branches to the upstream main in order to make pull requests, do I have to merge upstream/main with each local branch? Or do I have to merge the local main with all the branches? And How to update my remote fork?
It depends if you plan to:
mainand then create a PR from yourmainIf you plan to have to separate PR with 1 feature each then you should integrate the upstream target branch (not always
main) into your feature branches. It's entirely OK to keep your feature branches in sync with upstream with or without going via yourmain.The
mainbranch is not special per se and if you are not planning to use yourmainbranch there is no requirement to keep it in sync withupstream. Yourmainis only special if you make it special.It's worth remembering that there is no technical requirement to merge the
target->featurebefore you mergefeature->target; especially if changes are done in different parts of the code. You can just mergefeature->targetand use this merge to see if there are conflicts.Merging
target->featurefirst allows us detecting conflicts early, but also it allows to test the codebase with changes from both branches before the actualfeature->targetmerge. Sometimes two changes - even if they are in different parts of the code base (i.e. no conflicts) - don't work well together.