DEV Community

Cover image for How To Enable Git Auto Completion in Apple Terminal
Neeraj Gupta for DSC CIET

Posted on

How To Enable Git Auto Completion in Apple Terminal

If you are a Mac user and you are using git you might have faced issue with auto completion in git commands. I was searching through the internet and perform these steps in order to enable git auto completion on my mac because it was really frustrating for me without auto-completion in git. I will tell you how you can also enable it on your Mac in some easy steps.

Steps to Enable Git Auto Completion in MacOS

  1. Open the terminal on you Mac.
  2. Type
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash > ~/git-auto-complete.bash
Enter fullscreen mode Exit fullscreen mode

command and press Enter. This will create an auto completion script in your system's root directory with name git-auto-complete.bash.

  1. Type
vi ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

and press enter to open bash_profile in vim.

  1. When vim editor will be opened press i to go to INSERT mode.
  2. Paste source ~/git-auto-complete.bash in editor.

Output will look something like this.

source ~/git-auto-complete.bash
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
"~/.bash_profile" 1L, 32C
Enter fullscreen mode Exit fullscreen mode
  1. Press ESC key and insert mode will be exited.
  2. Press Shift + : and a colon will appear and type wq and press enter this will save the above written line in this file.
  3. Now close your terminal and open again.

Congrats you just got auto completion feature in git in your Mac.

Top comments (3)

Collapse
 
neeraj15022001 profile image
Neeraj Gupta

hey guys as of 2023 you can use oh my zsh for OSX along with plugins which include autocomplete plugin

ohmyz.sh/
github.com/ohmyzsh/ohmyzsh/wiki/Pl...

Collapse
 
markhu profile image
Mark

This script worked fine for me in June 2021 under macOS Big Sur version 11.4 using bash shell. Note that Zsh seems to be the new default, and will need a different completion scheme.

Collapse
 
sankalpanand profile image
sankalpanand

2021 Update. This will give you an error -
this script is obsolete, please see git-completion.zsh