Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does git store the last checked out branch?

Tags:

git

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

like image 230
Ram Rachum Avatar asked Sep 13 '16 08:09

Ram Rachum


1 Answers

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 ...
like image 126
LeGEC Avatar answered Sep 30 '22 11:09

LeGEC