By default, Git doesn't come with auto-complete for Git commands.
Auto-complete on Git commands helps the users to get comfortable with users who want to use Git more from command line.
- Grab ‘git-completion.bash’ script and place it in our home directory
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash - Now add the above script to your ‘~/.bash_profile' (or) '~/.zshrc', so that this scripts enables the auto-complete feature everytime during startup. This should work for both bash and zsh shells.
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi - To get this into effect, you need to restart all the existing terminals.
- If you don't want to restart your existing terminal, you can source the bash profile manually to have the changes active.
- You are all done now! Now type ‘git’, ‘space’, ‘tab’, you’ll get a list of all the possibilities. Same thing if you do ‘git checkout tab’ or ‘git checkout first few letters of branch name tab’.
- Happy coding!! 👍