Set Up Git

Now that you have Git installed, it’s time to configure your settings. To do this you need to open the Terminal.

Username

First you need to tell git your name, so that it can properly label the commits you make.

git config --global user.name "Your Name Here"# Sets the default name for git to use when you commit

Email

Git also saves your email address into the commits you make. We use the email address to associate your commits with your GitHub account.

git config --global user.email "your_email@youremail.com"# Sets the default email for git to use when you commit

Good to know: You don’t have to use your real email address. Git is actually very relaxed about the email setting. While it requires it to be set, it doesn’t force you to use a valid address. Many users use a more generic “user@server” format. This allows you to identify who made the commit, and from where, without exposing your email address to anyone that has access to the repo.

Password caching

The last option we need to set will tell git that you don’t want to type your username and password every time you talk to a remote server.

Good to know: You need git 1.7.10 or newer to use the credential helper

To use this option, you need install the osxkeychain credential helper and tell git to use it.

If you installed git using homebrew, you should already have the osxkeychain helper. You can verify this by trying to run it:

git credential-osxkeychain# Test for the cred helper
# Usage: git credential-osxkeychain <get|store|erase>

If you do not have the helper, you can download it with curl:

git credential-osxkeychain# Test for the cred helper
# git: 'credential-osxkeychain' is not a git command. See 'git --help'.

curl -s -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain# Download the helper

chmod u+x git-credential-osxkeychain# Fix the permissions on the file so it can be run

sudo mv git-credential-osxkeychain /usr/local/bin# Move the file so git can access it
# Password: [enter your password]

To tell git to use osxkeychain, simply set the global git config:

git config --global credential.helper osxkeychain# Set git to use the osxkeychain credential helper

The next time you clone an HTTPS URL that requires a password you will be prompted for your username and password, and to grant access to the OSX keychain. After you’ve done this, the username and password are stored in your keychain and you won’t be required to type them in to git again.

 

Advertisements