Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mac OS X - Install Git Completion
URL="https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash"
PROFILE="$HOME/.profile"
echo "Downloading git-completion..."
if ! curl "$URL" --silent --output "$HOME/.git-completion.bash"; then
echo "ERROR: Couldn't download completion script. Make sure you have a working internet connection." && exit 1
fi
SOURCE_LINE="source ~/.git-completion.bash"
if [[ -f "$PROFILE" ]] && grep -q "$SOURCE_LINE" "$PROFILE"; then
echo "Already added to bash profile."
else
echo "Adding to bash profile..."
echo "$SOURCE_LINE" >> "$PROFILE"
fi
echo "Reloading bash profile..."
source "$PROFILE"
echo
echo "Successfully installed."
echo "Git auto-completion should be all set!"
@abellmann

This comment has been minimized.

Copy link

commented Jul 25, 2011

added fork gist: 1105203 : the url did not work anymore. i modified the url there to use raw url of github

@johngibb

This comment has been minimized.

Copy link
Owner Author

commented Aug 17, 2011

I incorporated your changes, hope you don't mind. I can't seem to figure out a way to merge your changes with a gist a la pull request, so I just manually made the same edit you did. Hope you don't mind!

@NewAlexandria

This comment has been minimized.

Copy link

commented Feb 23, 2012

I get a pointer malloc error when the source "$PROFILE" line execs. That's not my specialty, but if others have this issue I'd be interested to know why. Otherwise the script execs fine (if you use .profile in bash)

@ajmichels

This comment has been minimized.

Copy link

commented Feb 14, 2014

@johngibb I ran this code and now my .profile script doesn't source when I open terminal. Any ideas? It works when I source it manually but it isn't doing it automatically anymore.

@ajmichels

This comment has been minimized.

Copy link

commented Feb 14, 2014

NM. I recently added a .bash_profile file which is now running instead of my .profile script. http://stackoverflow.com/questions/18773051/how-to-make-os-x-to-read-bash-profile-not-profile-file

I added "source ~/.profile" to .bash_profile and everything is happy again.

And the git completion is working. :)

@vicaya

This comment has been minimized.

Copy link

commented Aug 13, 2014

You'll need to add -L to the curl command to follow redirect now

@tashia

This comment has been minimized.

Copy link

commented Nov 6, 2015

Thanks! I am glad I found this one! I have tried so many links, this one finally make the autocompletion work!

@Sudharma

This comment has been minimized.

Copy link

commented Sep 15, 2016

Thanks worked for me on Mac.

@Kiodaddy

This comment has been minimized.

Copy link

commented Jun 20, 2017

Thanks working fine on Mac, i was having issue but corrected it.

@Maxon4eg

This comment has been minimized.

Copy link

commented Aug 28, 2017

Thank you !
works on mac

@ghost

This comment has been minimized.

Copy link

commented Jan 18, 2018

Thank you!
It works for me on mac.

@dnlglsn

This comment has been minimized.

Copy link

commented Feb 1, 2018

Thanks! This works on OSX high sierra too.

@A6Brgeuka

This comment has been minimized.

Copy link

commented Mar 22, 2018

works well, ty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.