Wednesday, 4 November 2020

Auto Complete Git Commands on Mac OS X

 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. 

  1. 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

  2. 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
  3. To get this into effect, you need to restart all the existing terminals. 
  4. If you don't want to restart your existing terminal, you can source the bash profile manually to have the changes active.
  5. 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’.
  6. Happy coding!! 👍

No comments:

Post a Comment

Update node.js & npm packages to latest/stable/<version>

Upgrade Node.js and npm: sudo npm cache clean -f  (force) clear you npm cache sudo npm install -g n  install  n  (this might take a while) s...