Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Put this in your bashrc:

    source /usr/share/bash-completion/completions/git
And you can type "git br<tab>" to write "git branch", "git checkout fun<tab>" to write "git checkout funky-feature", "git log --na<tab>" to write "git log --name-only" etc.

Pretty much every time you press <tab> somewhere while writing a git command, it does the right type of completion. And hitting <tab> multiple times lets you toggle through the options. So you learn git along the way.

This was one of my most enjoyable productivity jumps when it comes to using git.




On debian this is the default behavior.


Same in Ubuntu.

Bash completion on Ubuntu/debian is out of this world. I can do things like

lxc exec <TAB>

and get a list of currently running containers.


Fun fact: Ubuntu is a derivative of Debian!


Yeah, but they also have added some stuff that is not part of standard Debian.


git has a whole bash library for autocompletion stuff (like complete ref, complete tree). You can even use it when writing your own commands.


If you're on macOS, update your bash and install bash-completions and git. The path above is likely wrong if you're using a package manager: for MacPorts you want to source /opt/local/etc/profile.d/bash_completion.sh, and for Homebrew it's $(brew --prefix)/share/bash-completion/bash_completion (the install process will tell you what to use).


My brew has it in /usr/local/etc/bash_completion.d/



Here's mine:

    [alias]
      git = !cd -- ${GIT_PREFIX:-.} && git
This turns my most common typo (starting to type a git command, thinking about it, typing 'git' again) into what I wanted it to be.


  [help]
      autocorrect = 1
This one is very useful too.


I don't know why I never thought to look for more completions for git. This is a great tip!




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: