Branches are an amazingly powerful tool in Git, however it can be difficult to switch between them if you have to remember their names. Tab completion allows you to see all of your branches (or all of the branches that match the letters you’ve typed so far) at once.
Shawn O. Pearce wrote some great code to add tab completion to the git command line. It works in Bash terminals, including the command line on Macs.
How Git Tab Completion Works
When working on the command line and you type
git checkout followed by hitting
you’ll see a list of all of your branches.
Example of All Branches in my Local Repo
Auto-complete When You Know How it Starts
It really gets awesome when you start the name of the branch and then use tab completion.
git checkout de followed by
will complete “de” to “develop” (the only branch that starts de).
If the name you start matches multiple branches, auto-complete will complete your line as much as possible and then list your options.
git checkout or # followed by <tab> will become git checkout origin/ # you can then hit <tab><tab> for a list of all branches # that start with "origin/"
Example of Branches in my Local Repo that Start with “origin/”
How to Set up Git Tab Completion
I’ve created Ironcode Git Enhancements, which is a set of enhancements including:
- Git Tab Completion
- Git Status inclusion in Command Prompt
- Git Shortcuts (e.g.
When setting up a new machine, I follow the Ironcode Git Enhancements Instructions. It’s the fastest way I’ve found to set up these features.
If you’re having trouble setting up Git or the Ironcode Git Enhancements, I am available for Git training and setup to get you on track.
original photo credit: Foam (license), modified to include Git Logo