datguy
datguy

Reputation: 643

what is the best way to change a Git repo's origin?

I cloned a read-only Git repo from GitHub onto my server. The next day, I forked that repo on GitHub. What are the steps to update the remotes on my repository and make sure everything on the server is up-to-date?

Is this the way to start? Is there anything else I need to to so that the clone will treat the new origin as if I had originally cloned from it?

git remote rename origin upstream
git remote add origin [email protected]:user/fork.git

Upvotes: 6

Views: 2905

Answers (1)

grawity_u1686
grawity_u1686

Reputation: 16572

The repository as a whole doesn't have such a setting – each individual local branch does; there is a per-branch setting for its "upstream" or "tracking" branch which acts as the default for pushing, merging, or the @{u} shortcut.

The preferred way to change it is via the -u option of git push or git branch:

  • Just change upstream branch:

    git branch -u origin/master master
  • Or, push to a remote branch and set it as the new upstream:

    git push -u origin master

It can also be done directly through repository configuration (which is how it used to be done before -u was implemented):

  • git config branch.master.remote origin

Upvotes: 7

Related Questions