2022/March 2022

Getting your forked repo up to date with main repo

hajinny 2022. 3. 13. 17:31

note: origin is your forked repo, upstream is the main repo.

 

Sometimes it suffices to just go into your forked repo on github and press that green button (fetch upstream -> fetch and merge). However, if there's a possible conflict in doing so, github will automatically say that you can't do that. What do you do then? You have some commits pushed to your branch on origin so you don't want to restart everything. 

 

Here, you essentially want to rebase your branch to latest main branch on upstream. There will be conflicts that you have to manually resolve on the way.

 

Go to the branch you want to update:

git checkout yourbranch

Then pull from forked repo

git pull --rebase upstream main

You will see that you have a merge conflict:

You will need to remove those '>>>' and those conflict indicating signs, then do git add on that file you successfully resolved conflicts for. Then you run:

git push --force

to rewrite history so that all your commits lay out after the latest upstream main commit.