74

I'm very new to Git, so facing some issues with it correct usage. Here is my scenario.

I have a fork of my master repository and cloned it into my local. In that, I have 2 branches for different fixes.

When I commit, I saw a statement in the git-we saying that I'm 3 commits ahead and around 20 commits behind.

I understand that my fork is not in sync with master. Also I need to merge the two branches too (or should i do it?)

I used the windows client to syncing. But seems I'm not following the Git way. So, I tried to follow the steps described in https://help.github.com/articles/syncing-a-fork/ which is giving me an error as follows (I'm using windows).

 $>git fetch upstream
 fatal: 'upstream' does not appear to be a git repository
 fatal: Could not read from remote repository.

 Please make sure you have the correct access rights
 and the repository exists.

I'm a bit confused. Please help me with steps I should follow in this scenario.

@HuStmpHrrr

Sorry for adding the details in comments I'll modify the question for readability

By executing the command:

  $>git remote  returning two values
  acme-development (which the name of my actual/main repository, from where I forked) and
  origin

Adding some more info.


After making a fetch, I tried a origin/master merge on to my master Please see the screenshot enter image description here

But, if I login to my Github online account, it is saying a different story.

enter image description here

My git client says that the local repo is up to date. But the online git says that we are 42 commits behind and 7 commits ahead.

4
  • 2
    how did you clone? i guess you mean git fetch origin. if you defined a upstream, git fetch alone would work. or most people actually prefer git pull.
    – Jason Hu
    Oct 2, 2015 at 17:21
  • i think you need to show us git remote.
    – Jason Hu
    Oct 2, 2015 at 17:22
  • $>git remote acme-development origin
    – kallada
    Oct 2, 2015 at 17:30
  • don't paste that in comment, but in your question. so you have two remotes, acme-development and origin. i bet it's origin. do git fetch origin instead.
    – Jason Hu
    Oct 2, 2015 at 17:32

6 Answers 6

100

The article you link to (though it may have changed since you asked) starts with a reference to https://help.github.com/articles/configuring-a-remote-for-a-fork/. If you complete this you will have a new remote repository named upstream pointing to the original repository which you forked, and git fetch upstream will work.

2
  • 57
    The only necessary command from the article is git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git, you can proceed git fetch upstream after the above command. Nov 22, 2019 at 2:08
  • @NgSekLong thanks, this helped with the upstream problem
    – CybeX
    Dec 3, 2019 at 21:10
20

So there's a few things to clarify:

  • Upstream is the conceptual name of the remote repository (or repositories) that exist. Most projects only have one upstream repository.

  • The name of the upstream repository can vary from project to project, but by convention is origin.

That said, I'm willing to bet that you got the name of your upstream repo and the upstream repo concept confused, and you should be executing git fetch origin. Verify with git remote; use the appropriate name from that list.

However, if you only have one upstream repo, performing git fetch will accomplish the same thing.

10

Here are the steps I followed today to solve that same problem

The steps below will enable you to link your git fork and the original repository so that you can pull changes from the original repository anytime it's updated. Go to the repository's page on github and click on fork (if you haven't done so already). Assuming you forked a repo called repo-name from https://github.com/account/repo-name then you get a copy (fork) of the repo on your own account under something like https://github.com/your-user-name/repo-name Then run the commands below on your terminal

  • git clone https://github.com/your-user-name/repo-name.git
    
  • cd repo-name
    
  • git remote add upstream https://github.com/account/repo-name.git
    
  • git pull upstream master
    
  • git branch --set-up-stream-to=upstream/master
    
  • git pull
    

When you make changes and wish to integrate it the original codebase, in order to add your changes to the original repo, you have to push to your fork first on github and send a pull request which will then be verified and merged to the codebase. Steps below.

  • git add .
    
  • git commit -m "commit message"
    
  • git push origin master
    

Then visit your account on github and click on your repo-name. On the page, you'll see a link to create pull request. Click on the link and create pull request which will then be reviewed and merged by the maintainer.

1
6

Just run the following command on your terminal

$ git remote add upstream {your upstream repository link here}

After this command run :

git remote -v

this command will show you your github repository path and upstream repository path .

example output:

origin  https://github.com/ {Your Github username} / {repository name} (fetch)
origin  https://github.com/ {Your Github username} / {repository name} (push)

upstream    https://github.com/ {Upstream github username} / {repository name} (fetch)
upstream    https://github.com/ {Upstream github username} / {repository name} (push)

1

You must get a fork of a git project then:

git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git,

you can proceed git fetch upstream

0

to turn your fork in a remote branch

git remote add upstream https://github.com/repo/original.git

every time when you want to update your main branch do this (you have to situed in the master or main branch and apply this command):

git fetch upstream && git fetch upstream --prune && git rebase upstream/master && git push -f origin master

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.