Skip to content

Instantly share code, notes, and snippets.

@magnusbae
Created April 8, 2014 20:05
Show Gist options
  • Star 50 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save magnusbae/10182865 to your computer and use it in GitHub Desktop.
Save magnusbae/10182865 to your computer and use it in GitHub Desktop.
How to make Git stop track a remote branch without deleting the remote branch.

You don't have to delete your local branch.

Simply delete your remote tracking branch:

git branch -d -r origin/<remote branch name> (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

That will make any push/pull completely unaware of origin/.

Source: http://stackoverflow.com/questions/3046436/how-do-you-stop-tracking-a-remote-branch-in-git

@karl-gustav
Copy link

git branch --unset-upstream to only remove the tracking.

@fernandoaleman
Copy link

Thanks, this was very helpful. 👍

@RoyBellingan
Copy link

+1

@PhilipOakley
Copy link

+1 the git pu branch was recently renamed hence $ git branch -d -r gitster/pu 👍

@ElectricRCAircraftGuy
Copy link

ElectricRCAircraftGuy commented Sep 6, 2020

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

I find this part ironic because it further causes confusion about branches and tracking branches and git fetch. git fetch updates your locally-stored remote-tracking branches to contain the latest changes from their respective remote branches. So, when you say there's no such concept of local tracking branches, only remote tracking branches, that's not quite true--it depends how you word it and what you mean, as that English is ambiguous.

This is because there is such a thing as local tracking branches if what you mean is a local (meaning: stored locally on your computer's hard drive) branch which is a tracking branch, meaning it tracks a remote branch. So, some people may say local tracking branch and mean a locally-stored branch which tracks a remote branch, and that is a true and correct statement. So, a better wording would be to say that git fetch updates your locally-stored remote-tracking branches with the latest changes from their respective remote branches which they track.

Also, this line was very helpful. Thank you! This is what I came here for. :). I just learned something:

git branch -d -r origin/<remote branch name> (This will not delete the branch on the remote repo!)

@ElectricRCAircraftGuy
Copy link

ElectricRCAircraftGuy commented Sep 6, 2020

I've expounded on my comments above in this answer I just wrote here: https://stackoverflow.com/questions/1778088/how-do-i-clone-a-single-branch-in-git/63761209#63761209

@PhilipOakley
Copy link

I'd agree that the terminology can be real tricky some times, especially when its the devs that write the docs, so assume everyone is not that far behind them in their understanding (one of the Kruger-Dunning effect corollaries).

The 'rtb' is a bit 'reverse polish' in that it's actually "the branch that tracks the remote (repository", but never really explained anywhere (in the sense you mentioned about the potential confusion) The glossary rtb is what we get.

fetch updates your locally-stored remote-tracking branches with the latest changes from their respective remote branches which they track.

Even this (rtb definition) subtly isn't quite right because of the confusion about what "latest" means, who does it and when (i.e. the rtb may be out of date, but the fetch and pull commands are the ones to actually do the update - the user needs to do the command, it's not automatic!)

@Sammeeey
Copy link

Sammeeey commented Mar 28, 2022

Thanks!

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

This helped me to get rid of my config entry

[branch "origin/testHeroku"]
	remote = origin
	merge = refs/heads/main

via
git config --unset branch.origin/testHeroku.remote
and
git config --unset branch.origin/testHeroku.merge


git branch -d -r origin/testHeroku deleted my testHeroku in .git\refs\remotes\origin
I got it back, using git pull from the connected local testHeroku branch.

But what I actually want to do is to delete the directory .git\refs\remotes\testHeroku.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment