10

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?

stdcerr
  • 13,725
  • 25
  • 71
  • 128
  • 2
    If you are getting a merge conflict, then you should resolve it and commit, before trying to assess whether or not that merge were successful. – Tim Biegeleisen Oct 25 '18 at 03:57
  • @TimBiegeleisen I resolved the conflict & committed the changes but still did not get the files in question, I redid the `git merge upstream/remote-branch` but only got `Already up-to-date` – stdcerr Oct 25 '18 at 04:44
  • Changes/content you might expect to be there can sometimes be removed during a Git merge. – Tim Biegeleisen Oct 25 '18 at 04:45
  • @TimBiegeleisen it was a couple new files added in the upstream branch... i don't see no reason why they should be removed during a merge – stdcerr Oct 25 '18 at 04:46

2 Answers2

13

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

b-fg
  • 3,959
  • 2
  • 28
  • 44
  • I resolved the conflict & committed the changes but still did not get the files in question, I redid the `git merge upstream/remote-branch` but only got `Already up-to-date` – stdcerr Oct 25 '18 at 04:45
  • do a `git fetch` and `git status` on the `upstream/master` branch and see what you get. – b-fg Oct 25 '18 at 05:46
  • I am sort of facing the same issue but dont see `upstream/master` branch being presented in the output as suggested above. – Krishna Oza Jun 09 '22 at 17:25
0

//fetch from upstream git fetch upstream git checkout main git merge upstream/main git push origin main

  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 25 '23 at 14:15