Git checkout last: How to return to your previous commit or branch fast
The build was broken. The deploy was stalled. You needed to jump to the last commit fast.
git checkout last is not a default Git command, but it is a pattern many developers need. Git keeps track of your commit history and pointers, which means you can return to the previous commit, the last branch, or the most recent state in seconds — if you know the right syntax.
When people search for Git checkout last, they usually mean one of three things:
- Checkout the last commit on the current branch.
- Checkout the previous branch you were on.
- Checkout a specific commit by reference.
Checkout the last commit
Run:
git checkout HEAD
HEAD is the pointer to the latest commit on your current branch. This is useful when you want to discard staged changes and return to the last committed code.
Checkout the previous branch
Run:
git checkout -
The dash switches back to the branch you were on before the current one. This is a shortcut for quick toggling between branches without typing their names.
Checkout a specific commit
Run:
git checkout <commit-hash>
Get the hash from git log or git reflog. This allows you to jump to any commit, including the last commit before a breaking change.
Checkout last commit using reflog
Run:
git checkout $(git reflog | head -n 1 | awk '{print $1}')
git reflog lists the recent history of HEAD. Parsing it can give you precise control to move back to the most recent recorded commit no matter the branch state.
Knowing how to Git checkout last efficiently reduces downtime during merges, hotfixes, and rollbacks. Short commands mean faster context switching and more time spent shipping code.
See this in action and run it live in minutes with hoop.dev — instant, secure, and ready for production workflows.