{"id":622,"date":"2013-08-22T12:45:31","date_gmt":"2013-08-22T16:45:31","guid":{"rendered":"http:\/\/wcarss.ca\/log\/?p=622"},"modified":"2013-08-22T12:55:17","modified_gmt":"2013-08-22T16:55:17","slug":"when-git-cant-checkout-a-remote-branch","status":"publish","type":"post","link":"https:\/\/wcarss.ca\/log\/2013\/08\/when-git-cant-checkout-a-remote-branch\/","title":{"rendered":"when git can&#8217;t checkout a remote branch"},"content":{"rendered":"<h1>Problem<\/h1>\n<p>Coworker has a workflow of:<\/p>\n<ol>\n<li><span style=\"line-height: 1.6;\">work on branch<\/span><\/li>\n<li><span style=\"line-height: 1.6;\">push branch and make PR of it<\/span><\/li>\n<li><span style=\"line-height: 1.6;\">delete local branch, checkout remote so that local is tracking remote<\/span><\/li>\n<li><span style=\"line-height: 1.6;\">carry on<\/span><\/li>\n<\/ol>\n<p>except here&#8217;s what happened in the checkout stage:<\/p>\n<pre>user@host repo-name (master)$ git checkout issue-XXXXX-dummy-name-for-blogpost\r\n error: pathspec 'issue-XXXXX-dummy-name-for-blogpost' did not match any file(s) known to git.<\/pre>\n<p>It&#8217;s an old branch he&#8217;s trying to check out, but he just did the deletion step in this a few minutes ago. He does this all the time and he&#8217;s very experienced, so this was a bit of a pickle. I turned my rubber duckie over in my hands. We ran through some possibilities: doing a git fetch, trying it in a clean git clone (it worked fine), trying git-gc in the clone to see if it would break it, etc. Eventually, we turned to google.<\/p>\n<h1>Research<\/h1>\n<p>My\u00a0<a title=\"pathspec did not match any files(s) known to git\" href=\"https:\/\/www.google.ca\/search?q=error%3A+pathspec+did+not+match+any+file(s)+known+to+git\">search<\/a>, yielded two <a title=\"Git: cannot checkout branch - error: pathspec '\u2026' did not match any file(s) known to git\" href=\"http:\/\/stackoverflow.com\/questions\/5989592\/git-cannot-checkout-branch-error-pathspec-did-not-match-any-files-kn\">stack<\/a> <a title=\"http:\/\/stackoverflow.com\/questions\/11247432\/error-pathspec-temp-versionx-did-not-match-any-files-known-to-git\" href=\"http:\/\/stackoverflow.com\/questions\/11247432\/error-pathspec-temp-versionx-did-not-match-any-files-known-to-git\">overflow<\/a> hits, and he told me about <a title=\"git checkout remote branch\" href=\"http:\/\/stackoverflow.com\/questions\/1783405\/git-checkout-remote-branch\">another<\/a>.<br \/>\nThey suggested checking <a title=\"cool, man pages, yeah\" href=\"https:\/\/www.kernel.org\/pub\/software\/scm\/git\/docs\/git-show-ref.html\">git show-ref<\/a>, and it we decided to diff the good and bad repo&#8217;s refs. The SO responses also turned up an explicit way to tell git to check out a remote branch locally and track it:<\/p>\n<pre>git fetch origin\r\ngit checkout -b test origin\/test<\/pre>\n<p>His refs had something like the following in them:<\/p>\n<h3>bad repo:<\/h3>\n<pre>user@host bad-repo-name (master)$ git show-ref\r\nddc955...0f61cb refs\/remotes\/experiment\/issue-XXXXX-dummy-name-for-blogpost\r\n86b183...ac388f refs\/remotes\/origin\/issue-XXXXX-dummy-name-for-blogpost<\/pre>\n<h3>good repo:<\/h3>\n<pre>user@host good-repo-name (master)$ git show-ref\r\n86b18399ad7cb01eeea74f5577c0a5dfe1ac388f refs\/remotes\/origin\/issue-20198-remove-easy-cloud-accounting-copy<\/pre>\n<h1>Solution<\/h1>\n<p>This led him to the realization that git must be doing some name-matching and hitting the first instance of the branch name. That ref line tells us that commit ddc955&#8230;0f61cb is ref&#8217;d as a branch with our name on a remote named &#8216;experiment&#8217;. The other line says that there is a different commit ref&#8217;d as a branch with our name on a remote named &#8216;origin&#8217;, which is what we <em>want<\/em> to check out.<\/p>\n<p>Here&#8217;s the problem, and it was the aha moment: the &#8216;experiment&#8217; remote no longer exists &#8212; this commit is old enough to have been used on a nascent form of this repo, when it was an experiment, moved from an existing svn repository. The issue is that the &#8216;experiment&#8217; commit can&#8217;t be checked out, and git (reasonably) gives up at that point.<\/p>\n<p>So he deleted the experiment branch and used the explicit form for checking out a branch from origin to track the remote. Problem solved.<\/p>\n<h1>Takeaway<\/h1>\n<p><span style=\"line-height: 1.6;\">For the future:<\/span><\/p>\n<ul>\n<li><span style=\"line-height: 1.6;\">testing with a clean clone is really useful for determining if your problem is in your repo or everywhere<\/span><\/li>\n<li><span style=\"line-height: 1.6;\">git show-refs is a reallllly useful tool for telling you all the things<\/span><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Problem Coworker has a workflow of: work on branch push branch and make PR of it delete local branch, checkout remote so that local is tracking remote carry on except here&#8217;s what happened in the checkout stage: user@host repo-name (master)$ git checkout issue-XXXXX-dummy-name-for-blogpost error: pathspec &#8216;issue-XXXXX-dummy-name-for-blogpost&#8217; did not match any file(s) known to git. It&#8217;s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[63,57,64],"_links":{"self":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts\/622"}],"collection":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/comments?post=622"}],"version-history":[{"count":6,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts\/622\/revisions"}],"predecessor-version":[{"id":631,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts\/622\/revisions\/631"}],"wp:attachment":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/media?parent=622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/categories?post=622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/tags?post=622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}