7

When I do git checkout -, git checks out the last branch I had checked out. Where is that information stored?

Ram Rachum
  • 77,567
  • 79
  • 223
  • 360

1 Answers1

4

It scans .git/logs/HEAD (the reflog for HEAD) for the last line looking like :

checkout: moving from <branchA> to <branchB>

the "last branch" is branchA


As said in the post linked by @SergioTulentsev :

git checkout - is a shorthand for git checkout @{-1}.

  • @{-1} is the branchA of the last checkout: ... line
  • @{-2} is the branchA of the previous to last checkout: ... line
  • etc ...
Community
  • 1
  • 1
LeGEC
  • 35,975
  • 2
  • 46
  • 87