When moving between Git branches I sometimes forget the name of a branch I was recently on. How can I display a list of recently checked out branches/tags/commits in order of checkout?
Use git branch --sort=-committerdate to display a list of all local branches and sort them based on the date of their last commit. Use arrow keys to navigate, press Q to exit.
The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.
You can use Git's reflog
to show recent movements in order of checkout: git reflog
Here's a script you can download and use via git recent
from inside any Git repository: https://gist.github.com/jordan-brough/48e2803c0ffa6dc2e0bd
$ (master) git recent -n 5 1) master 4) deleted-branch 2) stable 5) improve-everything 3) fun Choose a branch: 2 $ (stable) …
See the gist for more details/options.
Here's essentially what the script does to make the reflog output more usable:
$ git reflog | egrep -io "moving from ([^[:space:]]+)" | awk '{ print $3 }' | awk ' !x[$0]++' | egrep -v '^[a-f0-9]{40}$' | head -n5 master stable fix-stuff some-cool-feature feature/improve-everything
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With