gitpullgit-fork

How to change fetch URL of a git repository.


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


Solution

  • 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?"