Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the remote a branch is tracking?

Tags:

git

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 
like image 654
joachim Avatar asked Feb 02 '11 18:02

joachim


People also ask

How do I stop a remote branch from tracking?

Simply delete your remote tracking branch: git branch -d -r origin/<remote branch name> (This will not delete the branch on the remote repo!) That will make any push/pull completely unaware of origin/.

How can I tell which remote branch I am tracking?

There is a command that gives you about all tracking branches. And to know about the pull and push configuration per branch you can use the command git remote show origin. and you can use -sb option for seeing the upstream. Hope this information will help you to find which branch is tracking.

How do I change my upstream remote?

The easiest way to set the upstream branch is to use the “git push” command with the “-u” option for upstream branch. Alternatively, you can use the “–set-upstream” option that is equivalent to the “-u” option. As an example, let's say that you created a branch named “branch” using the checkout command.


1 Answers

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 
like image 88
urschrei Avatar answered Sep 22 '22 18:09

urschrei