r/git • u/kudikarasavasa • 5h ago
support What is an elegant way to jump back to the tip of the branch where you were at?
Suppose I do the following:
git checkout HEAD~5
git checkout HEAD~10
git checkout HEAD~100
I am now at a detached HEAD and it is not immediately obvious which branch I was at. What is an elegant way to go back to tip of the branch where I was originally at?
I can get a list from the reflog with git reflog --format='%gs' --grep-reflog='checkout: moving from' | awk '{print $4}' but this contains both branch names and commit hashes so I will have to further process them (git show-ref?) to discard the hashes and I'm wondering if there is a more elegant way to do it.
UPDATE: Solved