Installing Git

By Vishvesh Patel · DevOps EngineerUpdated September 16, 2026

Install Git on macOS, Linux and Windows, then configure what matters. Identity, default branch, editor, and .gitattributes for line endings.

Why Installation and Setup Matter

Installing Git is quick, but good initial configuration saves time every day. Your name and email appear in commits, your editor opens when Git needs input, and your default branch name affects new repositories.

A clean setup helps you avoid confusing commit authors, awkward editor prompts, and inconsistent branch names across projects.

Tip: Configure Git once on your machine before starting real work. It prevents small problems from becoming repeated annoyances.

Installing Git on macOS

On macOS, the easiest path is often to install the Xcode Command Line Tools. If Git is missing, macOS may prompt you automatically when you run git.

Check first:

git --version

If Git is not installed, you can use:

xcode-select --install

If you use Homebrew, you can also install Git with:

brew install git

After installation, verify it:

git --version

Installing Git on Linux

Git is available through most Linux package managers.

Ubuntu or Debian

sudo apt update
sudo apt install git -y

Fedora

sudo dnf install git -y

CentOS or RHEL

sudo yum install git -y

Arch Linux

sudo pacman -S git

Then confirm the installation:

git --version

Installing Git on Windows

On Windows, the most common option is Git for Windows, which includes Git Bash and useful command-line tools.

  1. Download Git for Windows from the official installer.
  2. Run the installer.
  3. Accept the defaults unless your team has specific requirements.
  4. Open Git Bash or Command Prompt and verify:
git --version

Git Bash is especially helpful because many tutorials and DevOps commands assume a Unix-like shell experience.

Note: If you work with VS Code, Git for Windows integrates well with its built-in terminal and source control features.

Configuring Your Identity

Git needs to know who you are so commits can record an author.

Set your global name:

git config --global user.name "Vish Patel"

Set your global email:

git config --global user.email "vish@example.com"

These settings apply to all repositories on your machine unless a repository overrides them.

Check your current config:

git config --global --list

Why This Matters

If your name or email is wrong, your commits may appear under the wrong identity on Git hosting platforms. That can make collaboration and auditing harder.

Setting Your Default Editor

Git sometimes opens an editor for commit messages, merge messages, or rebase instructions. Setting your preferred editor makes those workflows smoother.

For VS Code:

git config --global core.editor "code --wait"

For Vim:

git config --global core.editor "vim"

For Nano:

git config --global core.editor "nano"

The --wait flag is important for VS Code because Git must pause until you finish editing.

Choosing a Default Branch Name

Many teams now use main instead of master as the default branch name.

Configure new repositories to start with main:

git config --global init.defaultBranch main

Now when you run git init, the initial branch will be main.

Verify it:

git config --global init.defaultBranch

Useful Optional Setup

Here are a few optional settings beginners often appreciate.

Show Helpful Colors

git config --global color.ui auto

Cache Credentials Temporarily on macOS or Linux

git config --global credential.helper cache

Use the Windows Credential Manager

On Windows, Git for Windows can help manage stored credentials depending on your install options.

Tip: Be careful storing credentials directly in files. Use secure credential helpers or SSH keys when possible.

Local vs Global Configuration

Git configuration can exist at different levels:

  • System: applies to every user on a machine
  • Global: applies to your user account
  • Local: applies only inside one repository

For example, if one work project needs a company email, you can override it inside that repository:

git config user.email "vish@company.com"

To inspect all effective settings and where they came from:

git config --list --show-origin

A Good First-Time Setup Checklist

A practical first-time setup often looks like this:

git config --global user.name "Vish Patel"
git config --global user.email "vish@example.com"
git config --global core.editor "code --wait"
git config --global init.defaultBranch main
git config --global color.ui auto

Then verify:

git config --global --list

What You Should Remember

Installing Git is easy, but the important part is configuration. Set your identity, editor, and default branch right away. That gives you cleaner commits, better compatibility with team workflows, and fewer surprises when Git opens an editor or creates a new repository.

Once Git is installed and configured, you are ready to create or clone repositories and start tracking real work.

Test Your Understanding

Exercise 1: Verifying installation

Scenario: You are on a new macOS machine and want to confirm whether Git is already available before installing anything.

Question: Which command from the tutorial should you run first?

Exercise

Exercise 1: Verifying installation

Choose the command that checks whether Git is already installed.

Exercise 2: Choosing an editor

Question: Why does the tutorial recommend git config --global core.editor "code --wait" when using VS Code?

Exercise

Exercise 2: Choosing an editor

Identify why the --wait flag matters when configuring VS Code as the Git editor.

Exercise 3: Global vs local identity

Scenario: Your personal machine uses vish@example.com globally, but one company repository must use vish@company.com for commits.

Question: Which approach matches the tutorial?

Exercise

Exercise 3: Global vs local identity

Choose the correct way to override commit identity for just one repository.


Frequently Asked Questions

How do I check whether Git is already installed?

git --version prints the version if it is present. On macOS this can be misleading: the command may exist and trigger a prompt to install the Xcode Command Line Tools, or report an Apple-shipped build that lags well behind upstream. which git tells you where it came from, /usr/bin/git is Apple's, /opt/homebrew/bin/git or /usr/local/bin/git is Homebrew's. Install via Homebrew if you want current Git on a Mac.

What is the first thing to configure after installing Git?

Your identity, because Git refuses to commit without it and it is stamped permanently into every commit you make: git config --global user.name "Your Name" and git config --global user.email "you@example.com". Use the email associated with your hosting account, or your commits will not be attributed to you. Then set init.defaultBranch main to match what GitHub and GitLab expect, and core.editor to something you can exit.

Why does Git say "Please tell me who you are"?

No user.name or user.email is configured, so Git cannot author a commit. Set them globally with the two --global commands, or per repository without the flag when a project needs a different address. The error usually appears on a brand new machine, or after cloning into a repository with a local config that cleared the values. Commits already made under the wrong identity can be corrected with git commit --amend --reset-author, though only safely before pushing.

Should I install Git with Homebrew or use the version macOS ships?

Homebrew, if you use Git seriously. The Apple-supplied build is tied to Xcode Command Line Tools updates and is often several minor versions behind, which means missing newer commands and flags, git switch and git restore arrived relatively recently, for example. brew install git gives you current Git that updates with everything else you have installed. Make sure Homebrew's path precedes /usr/bin in your PATH so the new one actually wins.

What is the difference between Git for Windows and Git in WSL?

They are two separate installations that do not share configuration or credentials. Git for Windows provides Git Bash and integrates with Windows tooling; Git inside a WSL distribution is a Linux Git operating on the Linux filesystem. Mixing them causes real problems, line endings, file permissions and credential helpers all differ, so pick one per project and stay with it. If you develop inside WSL, use WSL's Git and keep repositories in the Linux filesystem rather than under /mnt/c, which is also much faster.

How should I handle line endings across Windows, macOS and Linux?

Add a .gitattributes file to the repository with * text=auto so Git normalises text files to LF in history while checking them out natively, plus explicit rules for files that must stay LF, *.sh text eol=lf in particular, since a shell script with CRLF fails inside a Linux container with a baffling "not found". Committing .gitattributes is better than relying on each person's core.autocrlf setting, because it makes the behaviour a property of the project rather than of whoever cloned it.

Continue Learning

Explore Related Topics

When it breaks

Related Resources