6 ms·
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>" t
by no_gravity 7y ago
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.
- dearrifling 7y agoOn debian this is the default behavior.
- panpanna 7y agoSame 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.
- paulddraper 7y agogit has a whole bash library for autocompletion stuff (like complete ref, complete tree). You can even use it when writing your own commands.
- johnhenry 7y agoFun fact: Ubuntu is a derivative of Debian!
- panpanna 7y agoYeah, but they also have added some stuff that is not part of standard Debian.
- BinaryIdiot 7y agoI don't know why I never thought to look for more completions for git. This is a great tip!
- GauntletWizard 7y agoHere'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.
- Seb-C 7y ago[help] autocorrect = 1 This one is very useful too.
- saagarjha 7y agoIf 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).