Mountain Lion Git Keychain Credentials September 05, 2012 Tweet
I’m writing this blog post since my google-fu didn’t seem to bring up decent directions anywhere.
So I recently upgraded to OS X 10.8 Mountain Lion and I’ve been working out the little kinks in setting up my development environment. I was suprised to find out that 10.8 comes out of the box with git installed. Git version 18.104.22.168 (Apple Git-31.1) to be exact. So I didn’t proceed with my usual
brew install git.
Then, for the first time ever, I’ve been forced to use HTTPS access for a project and learned that git, on it’s own, doesn’t do anything to try to remember my username and password for recurring access to a repository. A bit annoying, but some google seemed to indicate there was a overcome this. Github’s “Set Up Git” gets me in the right ballbark but being that I didn’t install git with homebrew the install path instructions are not right for system git (as the instructions suggest is possible) but no feedback on how to find out the right place.
You can put
git-credential-osxkeychain anywhere on your
$PATH and git will “do the right thing”. The
git config instructions will still apply.
To find the right information I followed the rabbit hole via the
credential.helper git configuration option which led me to
gitcredentials(7). To “Find a helper” that might be available to me,
gitcredentials(7) suggests running
git help -a to find a git command that’s already installed that begins with the string “credential-“. The command,
git help -a actually ends up being more helpful than just that though. Here’s the output for my git:
Ryans-MacBook-Pro:~ ryanbriones$ git help -a usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] [-c name=value] [--help] <command> [<args>] available git commands in '/usr/libexec/git-core' ------------------------------------------------- ...list of commands and helpers... See 'git help <command>' for more information on a specific command.
There are a couple of important things to note here. First, the system installed git commands are stored in
/usr/libexec/git-core. This is helpful, but a bit of an empty victory. This file is owned by
root.wheel and it’s a bit gross to go through the
sudo incantations needed to put this custom credential helper in this system path. Also, there are two built-in credential helpers: cache and store. Both of these have drawbacks that I didn’t want to deal with. YMMV. See
git help credential-cache and
git help credential-store to make your own decision.
I decided to play a hunch to get
git-credential-osxkeychain to work for me – would git possibly check other places to find “helper commands” – and my hunch paid off. I pulled down
/usr/local/bin (where my brew stuff and other custom stuff is installed) and run
git help -a again. This is appended to the output from before:
git commands available from elsewhere on your $PATH --------------------------------------------------- credential-osxkeychain
Yay! Now I can follow the rest of the instructions from the Github Set Up Git instructions and everything works.
Hopefully this helps someone else.