W3docs

Install Git

On this page, you will find useful information about Git installation learning how to install Git from source; how to install it on Mac, Windows and Linux.

Before you can clone a repository, make a commit, or open a pull request, Git has to live on your machine. This page covers every common way to install Git on macOS, Windows, and Linux, how to build it from source when you need the newest release, how to verify the install, and the one-time configuration every new install needs.

A quick way to find out whether Git is already installed is to open a terminal and ask for its version:

git --version
git version 2.43.0

If you see a version number, Git is installed and you can skip ahead to configuring your identity. If you get command not found (or Windows prompts you to install developer tools), pick your operating system below.

how to install git

How to Install Git on Mac

There are three common ways to install Git on macOS: the official Git for Mac installer, Homebrew, and MacPorts. Homebrew is the most popular for developers because it also keeps Git up to date with brew upgrade. The Apple Command Line Tools also ship a Git build — running git --version on a fresh Mac will offer to install them.

Mac Installer

This is the simplest way of installing Git on Mac. Here are the steps to follow:

  1. Download the latest Git for Mac installer.
  2. Open the downloaded package and follow the prompts to finish installing.
  3. Open the Terminal and run git --version to verify that the installation was successful:
git --version
git version 2.43.0

Once Git is on your machine, set your identity so your commits are attributed correctly.

Homebrew

If you have Homebrew installed, this is the easiest path to keep up to date:

  1. Open your terminal and install Git with Homebrew:

Installing Git via Homebrew

brew install git
  1. Verify the installation:

Install Git with Homebrew

git --version
git version 2.43.0

Later, upgrade to the newest release at any time with brew upgrade git.

MacPorts

Follow these instructions to install Git with MacPorts:

  1. Update MacPorts:

Install Git with MacPorts

sudo port selfupdate
  1. Search for the most recent Git ports and their variants:

Search Git ports and variants

port search git
port variants git
  1. Install Git together with bash completion, the macOS keychain helper, and the docs:

Installing Git with macOS keychain helper

sudo port install git +bash_completion +credential_osxkeychain +doc

The +credential_osxkeychain variant lets Git store your remote credentials in the macOS Keychain so you are not prompted for a password on every push.

How to Install Git on Windows

The recommended package is Git for Windows, which bundles the Git command line, Git Bash (a Unix-style shell), and an optional GUI.

  1. Download the most recent Git for Windows installer.
  2. Run the installer. The Setup wizard offers several choices — the defaults are sensible. Two worth noting:
    • Default editor: choose the editor you already use (VS Code, Notepad, Vim, …) for commit messages.
    • PATH environment: "Git from the command line and also from 3rd-party software" lets you run git from both Command Prompt/PowerShell and Git Bash.
  3. After installation, open Git Bash (or PowerShell) and verify:
git --version
git version 2.43.0.windows.1

How to Install Git on Linux

On Linux, install Git through your distribution's package manager. The package is almost always named git.

Debian / Ubuntu ( apt-get )

Debian, Ubuntu, and their derivatives use APT. Update the package index first so you get the latest available version:

Install Git on Debian/Ubuntu

sudo apt-get update
sudo apt-get install git

Then verify the installation:

git --version

git --version
git version 2.43.0

Fedora (dnf/yum)

Git packages are available via dnf. (Note: yum is deprecated in modern Fedora.)

  1. Install Git using dnf:

Install Git via dnf

sudo dnf install git
  1. Verify the installation:

Check git version

git --version
git version 2.43.0

Other distributions follow the same idea with their own package manager — for example sudo pacman -S git on Arch, or sudo zypper install git on openSUSE.

How to Install Git From Source on Linux

Distribution packages can lag behind the latest Git release. Building from source is the way to get the newest features the moment they ship — at the cost of installing build dependencies and recompiling on each update. You need libraries such as curl, zlib, openssl, expat, and gettext. On systems with dnf/yum or apt-get, install the dependencies first:

Dependencies on Fedora/RHEL (dnf/yum)

sudo yum install curl-devel expat-devel gettext-devel \
openssl-devel zlib-devel perl-devel asciidoc xmlto

Dependencies on Debian/Ubuntu (apt-get)

sudo apt-get install libcurl4-openssl-dev libexpat1-dev gettext \
libz-dev libssl-dev

To build Git's documentation in other formats (man pages, HTML, info), add these dependencies as well:

Install Git and add documentation formats

sudo dnf install asciidoc xmlto docbook2X
sudo apt-get install asciidoc xmlto docbook2x

Next, download a release tarball from the Git source releases, then compile and install:

Install Git, Compile and install

tar -zxf git-<version>.tar.gz
cd git-<version>
make prefix=/usr/local all
sudo make prefix=/usr/local install

After installation, verify that Git is in your PATH by running git --version. If the command is not found, add /usr/local/bin to your PATH environment variable.

If you already have a Git build available, you can fetch the latest source directly instead of downloading a tarball:

Fetching source code

git clone https://github.com/git/git.git

Configure Git After Installing

A fresh Git install does not know who you are. Before your first commit, set your name and email — Git records these on every commit you make. The --global flag stores them once for your user account so you do not repeat this in every repository:

Set your Git identity

git config --global user.name "Bob Smith"
git config --global user.email "[email protected]"

It is also common to set your default branch name and preferred editor:

Common one-time settings

git config --global init.defaultBranch main
git config --global core.editor "code --wait"

Check what is currently configured at any time:

List your configuration

git config --list

For a full tour of these settings and where Git stores them, see Git Config.

Verify the Installation

After installing on any platform, confirm Git is on your PATH:

git --version
git version 2.43.0

If you see command not found, the install directory is not on your PATH. On a source build the binary is usually in /usr/local/bin — add it to PATH and restart your terminal. The exact version number you see depends on what shipped with your installer or package, so it may differ from the examples above.

Next Steps

With Git installed and configured, you are ready to start working with repositories:

  • Git Repository — what a repository is and how Git tracks your project.
  • git init — create a brand-new repository.
  • git clone — copy an existing repository to your machine.
  • Generate an SSH Key — connect securely to remotes like GitHub without typing a password.

Practice

Practice
Which methods can be used to install Git on different operating systems?
Which methods can be used to install Git on different operating systems?
Was this page helpful?