Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch upstream and resolve conflicts for a forked branch locally?

I have forked a Github Repo and raised PR for some contribution. Before getting merged, some other commits were made to the parent repo. To fetch upstream I need to resolve conflicts with the upstream. How do I fetch upstream locally and resolve those changes?

like image 302
Riya Golani Avatar asked Oct 29 '25 17:10

Riya Golani


1 Answers

You can follow the GitHub docs for that, but a quick way to do it would be:

Assuming you created a fork and cloned your fork only:

First thing you need to do is to add a new remote that points to the upstream project.

In your local fork, run git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

Fetch the remote: git fetch upstream

Be sure that you are in your branch you want to merge and run git rebase upstream/<branch you want to merge to>

This will move your branch to and will add the commits from your branch on top of that.

If you encounter any merge conflicts in the process, you need to:

  • resolve the conflict(s)
  • git add the affected file(s)
  • git rebase --continue to continue with rebasing

Once you are done, use git push --force origin <your branch> (you need to use the --force as you changed the branch history if you previously pushed your branch)

like image 197
VANAN Avatar answered Nov 01 '25 12:11

VANAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!