Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you stop tracking a remote branch in Git?

How do you stop tracking a remote branch in Git?

I am asking to stop tracking because in my concrete case, I want to delete the local branch, but not the remote one. Deleting the local one and pushing the deletion to remote will delete the remote branch as well:

  • How do I delete a Git branch both locally and in GitHub?

Can I just do git branch -d the_branch, and it won't get propagated when I later git push?

Will it only propagate if I were to run git push origin :the_branch later on?

like image 814
Jason Cohen Avatar asked Jun 15 '10 15:06

Jason Cohen


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/.

What does tracking a remote branch mean?

Remote-tracking branches are references to the state of remote branches. They're local references that you can't move; Git moves them for you whenever you do any network communication, to make sure they accurately represent the state of the remote repository.

How do you check that the branch is tracking the remote branch?

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 close a remote branch?

To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .


1 Answers

As mentioned in Yoshua Wuyts' answer, using git branch:

git branch --unset-upstream 

Other options:

You don't have to delete your local branch.

Simply delete the local branch that is tracking the remote branch:

git branch -d -r origin/<remote branch name> 

-r, --remotes tells git to delete the remote-tracking branch (i.e., delete the branch set to track the remote branch). This will not delete the branch on the remote repo!

See "Having a hard time understanding git-fetch"

there's no such concept of local tracking branches, only remote tracking branches.
So origin/master is a remote tracking branch for master in the origin repo

As mentioned in Dobes Vandermeer's answer, you also need to reset the configuration associated to the local branch:

git config --unset branch.<branch>.remote git config --unset branch.<branch>.merge 

Remove the upstream information for <branchname>.
If no branch is specified it defaults to the current branch.

(git 1.8+, Oct. 2012, commit b84869e by Carlos Martín Nieto (carlosmn))

That will make any push/pull completely unaware of origin/<remote branch name>.

like image 169
VonC Avatar answered Sep 28 '22 22:09

VonC