Getting Started with Git

I recently had to help a couple co-workers set up Git on their computers so they can work with the various repositories that I’ve set up and so they can set up repositories of their own for projects that they work on. Since I had to put together some documentation for them, I thought I would share it here in case it might help someone out. And then I can refer back to it myself in case anything ever happens to my work or personal laptops that requires me to set my development environment up again.

The following outlines how to get up and running with Git on your development machine. You can install Git without using Homebrew, but I find that Homebrew makes it easier to stay up-to-date. This also assumes that you are familiar with Terminal (i.e. the command line).

1) Install Xcode command line tools. You don’t need the full version of Xcode … only the command line tools.

xcode-select —install

When prompted, install the command line tools software. This will happen outside of Terminal.

2) Install Homebrew. Homebrew is a package manager for OS X.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

If prompted to enter a password, enter the password you use to log into your machine. NOTE: You will not see any visual feedback when entering your password (i.e. no “dots” showing you typed a character).

3) Verify that Homebrew installed.

brew doctor

If you see the message “Your system is ready to brew”, Homebrew is functioning properly. If you receive any error messages, see below for possible resolutions.

4) Install Git via Homebrew.

brew update
brew install git

5) Verify that Git was installed by running the following command. It should tell you what version of Git was installed.

git --version

6) Run the brew doctor command again to make sure everything is still working properly.

7) Configure Git to use your name and email when committing to repositories. So you should use the email address associated with your account where the Git repositories you will be working on are (i.e. Bitbucket, GitHub).

git config --global user.name “Firstname Lastname"
git config --global user.email “your@email.com"

8) (OPTIONAL) Install and set up the git-credential-osxkeychain helper. See below for how to install the helper.

If you would rather not use this helper, you can modify your Bitbucket profile to set up the SSH key associated with your account. This does require the use of command line. Instructions can be found here.


You are now ready to use Git. You have 2 options …

  1. Execute commands via the command line
  2. Use a GUI interface to handle the commands.

I prefer the command line, but there are a few GUI interfaces out there. One that I’m familiar with is SourceTree, which is FREE. It was built by Atlasssian, who also developed Jira and Bitbucket (which are both products that we use at work).

This website gives a quick overview of the commands you will need to use to interact with a Git repository if you are going the command line route.


Resolving Homebrew Issues

To resolve a message of “Warning: /usr/bin occurs before /usr/local/bin”, run the following command, quit Terminal, and relaunch Terminal. This command creates a bash profile, which Terminal uses, and adds the path to the bin directory, which is where Homebrew installs things.

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

To resolve a message of “Error: No such file or directory – /usr/local/Cellar”, run the following command to create the directory. Including the sudo  command will require you to enter the password for your machine. This is used to create the directory using the root user account so that Homebrew can install what it needs to.

sudo mkdir /usr/local/Cellar

To resolve a message of “/usr/local/etc isn’t writable” or “Cannot write to /usr/local/Cellar” or a message saying that any directory inside “/usr/local” isn’t writable, run the following command. Again, including the sudo  command will require you to enter the password for your machine.

sudo chown -R `whoami` /usr/local

Then run the brew doctor  command again to verify the fixes worked.


How-To Install the git-credential-osxkeychain Helper

1) To see if you already have the helper installed, run the following command.

git credential-osxkeychain

If it gives you a “usage” statement, skip to #5.

2) Download the helper.

curl -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain

3) Move the helper to the /usr/local/bin directory.

sudo mv git-credential-osxkeychain /usr/local/bin/

4) Make the file an executable.

chmod u+x /usr/local/bin/git-credential-osxkeychain

5) Configure Git to use the helper.

git config --global credential.helper osxkeychain