joachim joachim - 1 month ago 16
Git Question

How do I change the remote a git branch is tracking?

The

central
repository had to be set up on a new server, so I created a new remote on my local repo, and pushed to that.

But now when I do
git pull
, it claims I am up to date. It's wrong—it's telling me about the old remote branch, not the new one, which I know for a fact has new commits to fetch.

How do I change my local branch to track a different remote?

I can see this in the git config file but I don't want to mess things up.

[branch "master"]
remote = oldserver
merge = refs/heads/master

Answer

Without deleting anything, using git v1.8.0 or later:
git branch branch_name --set-upstream-to your_new_remote/branch_name

Or you can use the -u switch:
git branch branch_name -u your_new_remote/branch_name

Using git up to v1.7.12:
git branch --set-upstream branch_name your_new_remote/branch_name

Comments