Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change fetch URL of a git repository.

Tags:

git

git-fork

pull

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

like image 924
hidar Avatar asked Dec 24 '17 10:12

hidar


People also ask

How do I change the URL of my git repository?

In order to change the URL of a Git remote, you have to use the “git remote set-url” command and specify the name of the remote as well as the new remote URL to be changed. For example, let's say that you want to change the URL of your Git origin remote.

How do I change my push URL?

Run the git remote set-url --add --push origin git-repository-name command where git-repository-name is the URL and name of the Git repository where you want to host your code. This changes the push destination of origin to that Git repository.

How do I add a URL to a git repository?

To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. The git remote add command takes two arguments: A unique remote name, for example, “my_awesome_new_remote_repo” A remote URL, which you can find on the Source sub-tab of your Git repo.


2 Answers

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

like image 123
VonC Avatar answered Oct 25 '22 22:10

VonC


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

like image 40
Divij Sehgal Avatar answered Oct 25 '22 21:10

Divij Sehgal