Skip to content

Instantly share code, notes, and snippets.

@jpalmieri
Last active May 26, 2023 08:16
Show Gist options
  • Save jpalmieri/078cbb0581de5c53f3b7 to your computer and use it in GitHub Desktop.
Save jpalmieri/078cbb0581de5c53f3b7 to your computer and use it in GitHub Desktop.
Autocomplete for git commands and branch names
Taken from this page: http://code-worrier.com/blog/autocomplete-git/
Step 1: download this bash script (make sure to name it ".git-completion.bash"):
https://github.com/git/git/blob/master/contrib/completion/git-completion.bash.
You can run this curl from your home directory to download it directly:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
Step 2: Place the file in your home directory
Step 3: add the following lines to your .bash_profile:
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
Step 4: Close all Terminal windows and reopen. If it still doesn't work, make the script executable:
chmod -X ~/.git-completion.bash (per this reference: http://apple.stackexchange.com/questions/55875/git-auto-complete-for-branches-at-the-command-line)
Then restart Terminal.
You should now be able to use tab to autocomplete git commands and branch names, just like files and directories.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment