git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to get rid of tracking branch?

From
Junio C Hamano <junkio@cox.net>
Date
Feb 14, 2007, 17:04 UTC
Message-ID
<7vsld8r7px.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<200702141335.41165.andyparkins@gmail.com>
Andy Parkins <andyparkins@gmail.com> writes:
Show 9 quoted lines
> On Wednesday 2007 February 14 13:24, Johannes Sixt wrote:
>> Call me clueless, but how the heck do I get rid of a tracking remote
>> branch? I've cloned a repo locally, but in the clone I don't want to
>> track all the topic branches of the origin. But git branch -d keeps
>> saying it doesn't find the remote branch:
>
>  $ git branch -r -d origin/repo-devel
>
> I suffered the same thing a while ago :-)

I think you would also need to futz with remote.origin.fetch that says "track all branches from remote", or your next pull will re-create them.

You probably have
	[remote "origin"]
        	url = ...
                fetch = +refs/heads/*:refs/remotes/origin/*
	[branch "master"]
        	remote = origin
                merge = refs/heads/master

You would change it to list the branch you want to track explicitly:

	[remote "origin"]
        	url = ...
                fetch = refs/heads/master:refs/remotes/origin/master

However, this has a subtle side effect. If you create a new branch, say "test", running "git pull" while on "test" will merge "master". This is not wrong per-se (it has been the traditional git-pull behaviour and if you want to use the remote branch that is not the one first listed on remote.origin.fetch line, you can set up branch.test.merge yourself), but it may surprise you because it is different when you use the globbing refspec on the remote.origin.fetch line.

So if you want to track only two remote branches, say 'master' and 'dev', and if you want to also have your own 'master' and 'dev' that builds on them, you would have something like:

	[remote "origin"]
        	url = ...
                fetch = refs/heads/master:refs/remotes/origin/master
                fetch = refs/heads/dev:refs/remotes/origin/dev
	[branch "master"]
        	remote = origin
                merge = refs/heads/master
	[branch "dev"]
        	remote = origin
                merge = refs/heads/dev

Then while on 'master', "git pull" will fetch from origin and merge their 'master' in, and while on 'dev' "git pull" will merge their 'dev' in.

Previous: Andy Parkins
Message 3 of 3 in “How to get rid of tracking branch?”
  1. Johannes SixtFeb 14, 2007
  2. Andy ParkinsFeb 14, 2007
  3. Junio C HamanoFeb 14, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.