Install Git on Mac OS X
There are several ways to install Git on a Mac. In fact, if you've installed XCode (or it's Command Line Tools), Git may already be installed. To find out, open a terminal and enter
git --version
.As a follow up to my post on my text editor setup, I wanted to write about the other key part of my development setup - my terminal. Unlike my relatively new text editor setup, my terminal configuration has followed me around for years - spanning over multiple jobs and even more computers. Function Shortcut; New Tab ⌘ + T Close Tab or Window ⌘ + W (same as many mac apps) Go to Tab ⌘ + Number Key (ie: ⌘2 is 2nd tab) Go to Split Pane by Direction ⌘ + Option + Arrow Key Cycle iTerm Windows ⌘ + backtick (true of all mac apps and works with desktops/mission control) Splitting: Split Window Vertically (same profile). It always strikes me that even though iTerm2 already supports tmux out-out-the-box, it still has all that title bar and tab bar. They are basically useless to me. So why not getting rid of it? ITerm2 is open-source anyway. You just have to clone the repo and edit a bit to get rid of the titlebar.
Apple actually maintain and ship their own fork of Git, but it tends to lag behind mainstream Git by several major versions. You may want to install a newer version of Git using one of the methods below:
Git for Mac Installer
The easiest way to install Git on a Mac is via the stand-alone installer:
- Download the latest Git for Mac installer.
- Follow the prompts to install Git.
- Open a terminal and verify the installation was successful by typing
git --version
: - Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
- (Optional) To make Git remember your username and password when working with HTTPS repositories, configure the git-credential-osxkeychain helper.
Install Git with Homebrew
If you have installed Homebrew to manage packages on OS X, you can follow these instructions to install Git:
- Open your terminal and install Git using Homebrew: Focus professional 1 11 0 6.
- Verify the installation was successful by typing which
git --version
: - Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
- (Optional) To make Git remember your username and password when working with HTTPS repositories, install the git-credential-osxkeychain helper.
Install Git with MacPorts
If you have installed MacPorts to manage packages on OS X, you can follow these instructions to install Git:
- Open your terminal and update MacPorts:
- Search for the latest available Git ports and variants:
- Install Git with bash completion, the OS X keychain helper, and the docs:
- Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
- (Optional) To make Git remember your username and password when working with HTTPS repositories, configure the git-credential-osxkeychain helper.
Install the git-credential-osxkeychain helper
Bitbucket supports pushing and pulling your Git repositories over both SSH and HTTPS. To work with a private repository over HTTPS, you must supply a username and password each time you push or pull. The git-credential-osxkeychain helper allows you to cache your username and password in the OSX keychain, so you don't have to retype it each time.
- If you followed the MacPorts or Homebrew instructions above, the helper should already be installed. Otherwise you'll need to download and install it. Open a terminal window and check:If you receive a usage statement, skip to step 4. If the helper is not installed, go to step 2.
- Use curl to download git-credential-osxkeychain (or download it via your browser) and move it to
/usr/local/bin
: - Make the file an executable:
- Configure git to use the osxkeychain credential helper.The next time Git prompts you for a username and password, it will cache them in your keychain for future use.
Install Git with Atlassian Sourcetree
Sourcetree, a free visual Git client for Mac, comes with its own bundled version of Git. You can download Sourcetree here.
To learn how to use Git with Sourcetree (and how to host your Git repositories on Bitbucket) you can follow our comprehensive Git tutorial with Bitbucket and Sourcetree.
Build Git from source on OS X
Building Git can be a little tricky on Mac due to certain libraries moving around between OS X releases. On El Capitan (OS X 10.11), follow these instructions to build Git:
- From your terminal install XCode's Command Line Tools (if you haven't already):
- Install Homebrew.
- Using Homebrew, install openssl:
- Clone the Git source (or if you don't yet have a version of Git installed, download and extract it):
- To build Git run make with the following flags:
Install Git on Windows
Git for Windows stand-alone installer
- Download the latest Git for Windows installer.
- When you've successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation. The default options are pretty sensible for most users.
- Open a Command Prompt (or Git Bash if during installation you elected not to use Git from the Windows Command Prompt).
- Run the following commands to configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
- Optional: Install the Git credential helper on WindowsBitbucket supports pushing and pulling over HTTP to your remote Git repositories on Bitbucket. Every time you interact with the remote repository, you must supply a username/password combination. You can store these credentials, instead of supplying the combination every time, with the Git Credential Manager for Windows.
Install Git with Atlassian Sourcetree
Sourcetree, a free visual Git client for Windows, comes with its own bundled version of Git. You can download Sourcetree here.
To learn how to use Git with Sourcetree (and how to host your Git repositories on Bitbucket) you can follow our comprehensive Git tutorial with Bitbucket and Sourcetree.
Install Git on Linux
Debian / Ubuntu (apt-get)
Git packages are available via apt:
- From your shell, install Git using apt-get:
- Verify the installation was successful by typing
git --version
: - Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
Fedora (dnf/yum)
Git packages are available via both yum and dnf:
- From your shell, install Git using dnf (or yum, on older versions of Fedora):or
- Verify the installation was successful by typing
git --version
: - Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create
Build Git from source on Linux
Debian / Ubuntu
Git requires the several dependencies to build on Linux. These are available via apt:
- From your shell, install the necessary dependencies using apt-get:
- Clone the Git source (or if you don't yet have a version of Git installed, download and extract it):
- To build Git and install it under
/usr
, runmake
:
Iterm2 Git
![Iterm2 Iterm2](https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/ITerm2_v2.0_screenshot.png/300px-ITerm2_v2.0_screenshot.png)
Fedora
Git requires the several dependencies to build on Linux. These are available via both yum and dnf:
- From your shell, install the necessary build dependencies using dnf (or yum, on older versions of Fedora):or using yum. For yum, you may need to install the Extra Packages for Enterprise Linux (EPEL) repository first:
- Symlink docbook2X to the filename that the Git build expects:
- Clone the Git source (or if you don't yet have a version of Git installed, download and extract it):
- To build Git and install it under
/usr
, runmake
:
Next up:
Setting up a repository
Start next tutorialSo, out of boredom, I decided to upgrade my shell and terminal to something closer to 2017, instead of living in the early 90s. Clearly I’e been using
bash
all these years - mostly on Ubuntu and lately on OSX. But I’ve always been lazy and complacent with the terminal. I’ve always wanted to set up fish
- Friendly Interactive SHell. for it’s git integration, and very rich interaction. Sure, all of this can be done on bash
or zsh
but I hate configuration, and combing hundreds of git repos for bashfiles
and find what works for me.While at
fish
, I also decided to upgrade the default Mac terminal
to iTerm2
. This led me to a journey through installing fonts all the way to picking up the theme that works for me. But again, no configuration to mess with.Installing fish
Logicly 1 10 0 download free. Since I have brew, I was able to simply do this
If you do not have brew, head over to fishshell.com for instructions on setting it up. They have MacPorts, Installer, and an executable.
Iterm 2 Github
Once installed, the default theme supports git repositories, in that, the prompt indicates the local repository state, has nice syntax highlighting on the command line, and typical things you’d expect from the shell of the 21st century.
You can see the prompt change, as well as a timestamp show up to the right of the window.
If you wish to make fish your default shell, add add
/usr/local/bin/fish
at the very top of /etc/shells
, and execute chsh -s /usr/local/bin/fish
. If not, then you can always type fish
in bash
.Iterm2 Gitlab
Installing omf
Given the richness of fish with themes and plugins, it’s best to use
omf
- Oh My Fish, which is more or less a package manager for fish.To install
omf
-Iterm2 Git Autocomplete
Once
omf
is installed, checking out themes etc. becomes a breeze. To do so, type omf
on the prompt to see the options. Typing omf theme
will show a big list, and in order to see what these themes look like, head over here to preview them.I liked
bobthefish
, and installed it like so -You can always switch back to
default
by typing omf theme default
. You can install many themes and switch back and forth between them till you’re comfortable with one of them.However, this theme (and many others) uses fonts that would need to be installed.
Installing Powerline Patched Fonts
Feel free to remove the
fonts
directory.Installing iTerm2
Downloaded and installed iTerm2, which is super simple to do.
Take a look at the Font Book, and pick the powerline font of your choice. I like
Ubuntu Mono
. You can type powerline
in the little search textbox in Font Book to shorten the list. Once picked, set the font here -Restart iTerm2, and you should be all set!
Iterm2 Github Plugin
Github integration
This image shows how the prompt changes as we make simple changes to a local git repo. I am using
bobthefish
theme. See the theme details on how the prompt indicates various states like locally committed but un-pushed changes, etc.As you can see, it is super helpful, with no configuration to get this going. This to me is one of the most useful and powerful features of
fish
.Now that you have
fish
and omf
set up, play with the many options and if you have never used it before, you’ll be surprised how modern and developer friendly this set up is. The depth of autocomplete going beyond just file names, auto-suggestion, history navigation, and syntax coloring makes working on the terminal so much productive and painless!