When I try to create a new branch tracking a remote branch, I get this:
$ git branch -t test origin/foo
error: Not tracking: ambiguous information for ref refs/remotes/origin/foo
The source seems to somehow search for branches to track and throws me out because it finds less more than one, but I don't exactly get what it's looking for since I already told it what to track on the command line.
Can anybody tell me what's going on and how to fix it?
Got it! The problem was that I have previously set up a remote with
--mirror
, for the purpose of having a backup / public copy of my repository.If you run
it does not only flag the remote as mirror (which is what I wanted for pushes), but also configures
remote.<mirror>.fetch
option for the mirror to+refs/*:refs/*
, which means that all of your branches suddenly "track" your mirror repository and any attempt to create a tracking branch is going to fail.(As an added bonus, running
git fetch <mirror>
is going to overwrite all your refs with old ones from your backup repo.)The solution that seems to fix this issue is setting
remote.<mirror>.fetch
to:
(which, I hope, means "never fetch anything"). This apparently fixes the tracking issue and eliminates the deadly fetch.None of the other fixes mentioned here worked for me. The one that ended up working was this:
After running the above, even though git complained, it did end up creating a local branch
test
but no upstream set.Now, I opened the
.git/config
file (which did not have any record of a branchtest
) and added the following manually:After which everything worked fine.
Nope: because it finds more than one matching remote branch, which means the function
remote_find_tracking()
returns more than one tracking branch for a given local branch ref.Is
some_remote_branch
not already tracked by one of your local branches?(a
git config -l
would allow you to check what you have currently have set up).(a
git branch -r
can also help to list your current remote-tracking branches. )Wrong, as illustrated by this thread:
Now:
The problem is, for git-merge:
Consider that
remote_find_tracking()
takes a single remote and a refspec with src filled, and returns the given refspec after filling its dst, if an appropriate tracking was configured for the remote, meaning git.May be it considers it already has a local following branch matching
some_remote_branch
. Do you have any local branch with that exact same name?Or, the other way around: your current branch has a remote branch with a similar name, which makes it a natural candidate for any
git-merge
: trying to make it track another remote branch would make thegit-merge
unable to choose which local branch to update/merge with changes of a remote.I got in a situation like this, but I do not know how. The listing from
git branch -av
showed me only a single remote tracking branch for the branch I cared about (origin/dev
).What I did to fix it was to use the hexadecimal commit hash instead of
origin/dev
:When I did the push with
-u
Git saidBranch dev set up to track remote branch dev from origin.
Subsequent pulls and pushes worked as I expected.I saw this also when I had two remote repo's with the same (default) fetch pattern (
fetch = +refs/heads/*:refs/remotes/origin/*
) and the same branches.I still haven't worked out how to fix it properly, since I want to continue to push/pull to both repo's, but manually adding the info to the project's
.git/config
works, e.g.: