Last updated: 2026-05-17

Installing and Configuring Git

Before you can use Git, you need to install it and configure it with your identity. This is a one-time setup — the configuration persists across sessions and projects until you deliberately change it.


Installing Git

macOS

The simplest way to get Git on macOS is to trigger the Xcode Command Line Tools installation. Open your terminal and run:

git --version

If Git is not already installed, macOS will prompt you to install the Command Line Tools, which includes Git. Follow the prompt and Git will be available once the installation completes.

If you want a more up-to-date version, you can download a dedicated macOS Git installer from the official Git website:

https://git-scm.com/download/mac

Linux

On Debian-based distributions (Ubuntu, Debian, Linux Mint):

sudo apt install git-all

On Fedora and RPM-based distributions (RHEL, CentOS):

sudo dnf install git-all

For other distributions, the Git website maintains installation instructions for most platforms at https://git-scm.com/download/linux.

Windows

Download the official Git for Windows installer from:

https://git-scm.com/download/win

The download starts automatically when you visit the page. Git for Windows installs Git Bash — a terminal environment that gives Windows users a Unix-like command-line experience. This is the recommended way to use Git on Windows, as most Git documentation and tooling assumes a Unix-style environment.

Verifying the Installation

Once installed, confirm Git is available by checking its version:

git --version
# Output: git version 2.x.x

First-Time Configuration

Git comes with a configuration tool called git config that lets you set variables controlling how Git looks and behaves. These settings are stored in three places, each with a different scope:

LevelFile LocationScopeFlag
System/etc/gitconfigEvery user on the machine--system
Global~/.gitconfigYour user account, all repositories--global
Local.git/configThe current repository only--local

Each level overrides the one above it. A local setting in a specific repository will always take precedence over your global setting, which takes precedence over the system setting.

For personal development machines, the global level is where you will do most of your configuration.


Setting Your Identity

The first thing to configure after installing Git is your name and email address. This is critical — every commit you create permanently records this information. It is how collaborators and project history identify who made each change.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

The --global flag means this applies to every repository on your machine. If you ever need a different identity for a specific project — say, a work email for a company repository — you can override it locally from inside that project's directory:

git config --local user.email "work@company.com"

Setting Your Default Editor

When Git needs you to write a message — such as during a commit or a merge — it opens a text editor. By default it uses whatever your system's default editor is, which on many systems is Vim. If you prefer something else, configure it explicitly:

# VS Code
git config --global core.editor "code --wait"

# Nano (simpler terminal editor)
git config --global core.editor "nano"

# Sublime Text
git config --global core.editor "subl -n -w"

The --wait flag for VS Code tells Git to wait until you close the file in the editor before proceeding — without it, Git moves on immediately and the commit message is empty.


Setting the Default Branch Name

When you create a new repository with git init, Git creates an initial branch. Historically this was named master. Since Git 2.28, you can configure the default name — and the current industry convention has shifted to main:

git config --global init.defaultBranch main

Setting this means every new repository you initialise will start with a branch called main rather than master, consistent with how GitHub and most modern platforms now name the default branch.


Checking Your Configuration

To see all your current configuration settings and the file they came from:

git config --list --show-origin

To check a specific setting:

git config user.name
git config user.email

If you ever get an unexpected value for a setting and aren't sure where it came from, the --show-origin flag will tell you exactly which configuration file is responsible:

git config --show-origin user.name
# Output: file:/home/wariz/.gitconfig    Wariz

Getting Help

If you need to look up what a Git command does or what options it accepts, Git has built-in documentation accessible entirely offline:

git help <command>       # Full manual page
git <command> --help     # Same as above
git <command> -h         # Concise quick-reference

For example:

git help config          # Opens the full config manual
git commit -h            # Shows a compact list of commit options

A Recommended Setup Checklist

Here is the complete first-time setup sequence for a new machine:

# 1. Confirm Git is installed
git --version

# 2. Set your identity
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

# 3. Set your preferred editor
git config --global core.editor "code --wait"

# 4. Set the default branch name
git config --global init.defaultBranch main

# 5. Verify everything looks correct
git config --list

Once these steps are done, your Git environment is ready. The configuration persists permanently — you only need to repeat this when setting up a new machine or when you want to change a setting.