4

Me and my team member are working on same repository. Someone create a branch from master called test_01, worked on that and commit, push to test_01 and merge to master. In the meantime some commit are done in master. Now I want to checkout that test_01 so that I write

 git checkout test_01 

and got a git error : pathspec 'test_01' did not match any file know to git .

Drop Shadow
  • 845
  • 3
  • 12
  • 28

1 Answers1

11

After a git fetch, check the list of the remote tracking branches with:

git branch -avv

If you see origin/test_01, a git checkout test_01 should work, since it is the equivalent of:

git checkout -b <branch> --track <remote>/<branch>

Or, since Git 2.23+, Q3 2019:

git switch <branch>

(through its "guess mode", that will be the same as git switch -c <branch> --track <remote>/<branch>)

But since it does not work, it is likely the test_01 branch was merged to master locally by the other developer, and only master was pushed.

You can try and look for the commit of that unnamed branch merged into master: see "Find merge commit which include a specific commit".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Thanks, this worked for me, but the initial `fetch` was the secret, otherwise you get the `did not match any file` error. Once you do the `fetch`, though, you're able to checkout the branch with the proper tracking as you indicated. – rjcarr Apr 06 '21 at 19:33
  • 1
    this is how's done ... and like someone said, adding `git fetch` as the first statement, rounds this out to nicely! thank you @vonc! – Goran B. Feb 10 '22 at 19:26