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:
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?
As mentioned in Yoshua Wuyts' answer, using
git branch
:Other options:
You don't have to delete your local branch.
Simply delete your remote tracking branch:
(This will not delete the branch on the remote repo!)
See "Having a hard time understanding git-fetch"
As mentioned in Dobes Vandermeer's answer, you also need to reset the configuration associated to the local 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>
.To remove the upstream for the current branch do:
This is available for Git v.1.8.0 or newer. (Sources: 1.7.9 ref, 1.8.0 ref)
source
The easiest way to do this is to delete the branch remotely and then use:
git fetch --prune (aka git fetch -p)
You can delete the remote-tracking branch using
as VonC mentions above. However, if you keep your local copy of the branch,
git push
will still try to push that branch (which could give you a non-fast-forward error as it did for ruffin). This is because the configpush.default
defaults tomatching
which means:(see http://git-scm.com/docs/git-config under
push.default
)Seeing as this is probably not what you wanted when you deleted the remote-tracking branch, you can set
push.default
toupstream
(ortracking
if you have git < 1.7.4.3)using
and git will stop trying to push branches that you have "stopped tracking."
Note: The simpler solution would be to just rename your local branch to something else. That would eliminate some potential for confusion, as well.
git branch --unset-upstream
stops tracking all the local branches, which is not desirable.Remove the
[branch "branch-name"]
section from the.git/config
file followed bygit branch -D 'branch-name' && git branch -D -r 'origin/branch-name'
works out the best for me.
The simplest way is to edit
.git/config
Here is an example file
Delete the line
merge = refs/heads/test1
in thetest1
branch section