23

I have a github profile and I forked someone's repository into mine. and locally I have cloned this repository using

git clone https://github.com/my-github-page/repo-name

Now, since some time has passed the original repo owner has update his repo, but mine is behind. So, if I would like to do git pull to merge his changes into mine. But I would like to push my changes from local to mine.

In simple terms, if I do git remote show origin I get this:

[root@localhost xxx]# git remote show origin
* remote origin
  Fetch URL: https://github.com/my-github-profile/xxx
  Push  URL: https://github.com/my-github-profile/xxx
  HEAD branch: master
  Remote branches:
    1.0          tracked
    master       tracked
    system_tests tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

Now I want to change the FETCH URL to the original src of the repo. Because the original is updated but my fork is behind

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
hidar
  • 5,449
  • 15
  • 46
  • 70

2 Answers2

41

You can try:

git remote set-url origin /original/repo
git remote set-url --push origin /your/fork

That way, only fetch references the original repo URL.

The other more traditional approach, of course, is to declare another remote, as I detailed in "What is the difference between origin and upstream on GitHub?"

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    @PeterHaddad yes, It seems appropriate considering the date – VonC Dec 24 '17 at 11:52
  • 2
    Works, but looks quite ugly IMO. I'd really expect `git remote set-url --fetch` option, so sad it doesn't exist – The Godfather Feb 19 '20 at 10:08
  • 2
    @TheGodfather That was discussed in https://public-inbox.org/git/xmqqftwp47nb.fsf@gitster-ct.c.googlers.com/T/ "remote: add --fetch option to git remote set-url", but... denied. – VonC Feb 19 '20 at 10:55
1

Taking references from the following question: github, update forked project

Do the following:

git remote add upstream <url of the repo you cloned from>

After this pull from upstream. This will pull all remote changes into your local copy.

If in future, you again need to pull changes from remote, you can pull from upstream again, this time without needing to add upstream url again.

Suggested Read-up: Syncing a fork

Divij Sehgal
  • 647
  • 2
  • 11
  • 26