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
If you're sane about it, editing the config file's safe enough. If you want to be a little more paranoid, you can use the porcelain command to modify it:
Of course, if you look at the config before and after, you'll see that it did exactly what you were going to do.
But in your individual case, what I'd do is:
That is, if the new server is going to be the canonical remote, why not call it origin as if you'd originally cloned from it?
You could either delete your current branch and do:
Or change change remote server to the current one in the config
In latest git version like 2.7.4,
git checkout branch_name
#branch name which you want to change tracking branchgit branch --set-upstream-to=upstream/tracking_branch_name
#upstream - remote nameBased on what I understand from the latest git documentation, the synopsis is:
This usage seems to be a bit different than urschrei's answer, as in his the synopsis is:
I'm guessing they changed the documentation again?
Another option to have a lot of control over what's happening is to edit your configurations by hand:
or the shorthand
Then edit the file at will, save and your modifications will be applied.
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 v1.7.12 or earlier:
git branch --set-upstream branch_name your_new_remote/branch_name