Over a million developers have joined DZone.

Solved: Git Won't Check Out a Path It Autocompleted

DZone's Guide to

Solved: Git Won't Check Out a Path It Autocompleted

Strange Git behavior when checking out on remote repos, solved.

· DevOps Zone
Free Resource

Download “The DevOps Journey - From Waterfall to Continuous Delivery” to learn about the importance of integrating automated testing into the DevOps workflow, brought to you in partnership with Sauce Labs.

One of my Git repositories has developed a tendency to refuse to checkout a feature branch locally that exists on the remote repo. My Git bash completion works, but then strange things happen! It turned out to be that I had two remotes with the same refspec, so I thought I'd write down the behaviour I saw and hopefully help someone else to fix this problem faster if they see it.

It started with not being able to check out a branch. I would see that my colleague had created feature/cute-labels and usually I can just check out the branch name and Git makes a local branch from the remote one and sets it up to track, which is what I expected. But this time, even though the branch name autocompleted:

$ git checkout feature/cute-labels
error: pathspec 'feature/cute-labels' did not match any file(s) known to git.


So next I tried to create a branch and set what it tracked:

$ git checkout -b feature/cute-labels
Switched to a new branch 'feature/cute-labels'
$ git branch -u origin/feature/cute-labels
error: Not tracking: ambiguous information for ref refs/remotes/origin/feature/cute-labels

Ambiguous information ... interesting. I looked in .git/config and sure enough I had two remotes which both had the same fetch line:

fetch = +refs/heads/*:refs/remotes/origin/*

We had a problem with our jump host one day and I'd added the https version of the repo as a separate remote but with the same pathspec. Since Git didn't know which remote I meant (and can't tell that they are the same thing), it didn't know what to do. This was a weird little problem that's been irritating me for probably a few weeks, so I was glad to understand it and be able to sort it out!

Discover how to optimize your DevOps workflows with our cloud-based automated testing infrastructure, brought to you in partnership with Sauce Labs

git ,source control

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}