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

@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