Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I merge changes from an upstream branch to my fork's branch

I want to pull changes from an upstream repo's branch. I have set the upstream repo using:

git remote add upstream http://URL-of-master-repo.git 

and then I tried to pull the changes using

git checkout my-local-branch
git fetch upstream remote-branch
git merge upstream/remote-branch

but the files still didn't appear on my disk, but I get a conflict:

Auto-merging minimal-build-config.cmake
CONFLICT (content): Merge conflict in minimal-build-config.cmake
Automatic merge failed; fix conflicts and then commit the result.

How do I properly resolve the conflict to be able to fetch the files from the upstream branch?

like image 559
stdcerr Avatar asked Dec 14 '25 00:12

stdcerr


2 Answers

A good practice is to have this structure, which looks like you do, but is good to explain for clarification purposes:

origin  https://github.com/your-username/forked-repository.git (fetch)
origin  https://github.com/your-username/forked-repository.git (push)
upstream    https://github.com/original-owner-username/original-repository.git (fetch)
upstream    https://github.com/original-owner-username/original-repository.git (push)

So origin is your fork and upstream the original repository. Then use

git fetch upstream

And you will get this output

From https://github.com/original-owner-username/original-repository
 * [new branch]      master     -> upstream/master

where you have now a branch called upstream/master which tracks the original repo.

Then checkout to your local fork branch and merge

git checkout master
git merge upstream/master

If you have conflicts (as it seems you do) fix them and commit the changes.

Source

like image 158
b-fg Avatar answered Dec 16 '25 20:12

b-fg


//fetch from upstream
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
like image 44
JOHN OGINGO Avatar answered Dec 16 '25 19:12

JOHN OGINGO



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!