Git

Git git

Git is a distributed version control system. (But you knew that already, because you totally completed a Git tutorialright?) If you have previously installed Xcode and its command-line tools, you may already have Git installed. Find out by entering the following command:

user@localhost ~
 

git --version
git version 2.12.2

If you see something like git version 2.12.2, then you already have Git. If not, skip to the next section to install Homebrew. If you have Git, but the version number is lower than 2.12.2 (as of April 11, 2017), then your version of Git is out of date. Continue to the next step to install Homebrew.

If your Git version is up-to-date, skip to the Git Configuration section.

GitHub Desktop

GitHub Desktop is a very nice, free graphical interface for Git. Although we’ll use Git from the command-line a great deal, we’ll also look at how GitHub Desktop can make certain tasks easier.

Homebrew

Homebrew is a package manager for macOS. That is, it manages the installation of certain software—especially UNIX tools—and the installed versions of that software.

Install Homebrew with the following command:

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

Installing Git with Homebrew

If you do not have Git installed at all, or if your version is out of date, run the following command to install the latest version:

user@localhost ~
 
brew install git

Now check your Git version again.

user@localhost ~
 
git --version

You should see an up-to-date version number.

The next time a new version of Git is released, just type the following commands:

user@localhost ~
 
brew update           # This updates Homebrew so it knows about the latest versions.
brew upgrade git      # This upgrades Git itself.

Configuring Git

Next, tell Git what name and email address it should use to sign code that you’ve authored. While you’re at it, tell it to use Code as the editor. Enter the following commands, substituting your actual name and email address:

user@localhost ~
 
git config --global user.name "Your Full Name"
git config --global user.email "youremailaddress@example.com"
git config --global core.editor "code --wait"