Skip to content

Instantly share code, notes, and snippets.

@magnusbae
Created April 8, 2014 20:05
Show Gist options
  • 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

@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