How to Install and Set Up Git on Windows, Mac and Linux

Setting up Git involves installing it on your system and configuring global settings like user name and email for proper commit tracking.

Installing and Setting Up Git

Before you can start tracking changes and collaborating on projects, you need to install Git on your system and configure a few essential settings. This process takes only a few minutes, but doing it correctly from the beginning ensures that your commits are properly identified and your environment is ready for real development work from day one. Think of it as setting up your workspace before starting a new project—a small upfront effort that prevents countless headaches later.

Git works seamlessly on all major operating systems, and the installation process is straightforward on each one. Once installed, a small set of configuration commands personalizes Git to your identity and preferences. If you are completely new to version control, it is worth reading through the Git introduction first to understand what Git does before setting it up. Having that foundational knowledge makes each configuration step feel more meaningful rather than just following instructions blindly.

Check if Git Is Already Installed

Many systems come with Git pre-installed, particularly on macOS and Linux. Before downloading anything, open your terminal or command prompt and run the following command to check whether Git is already available on your machine. This simple check takes just a moment but can save you from unnecessary downloads and installations.

git --version

If Git is installed, you will see the version number printed in the terminal, something like git version 2.39.0. If the command is not recognized, you will need to install Git using the method appropriate for your operating system. Either way, confirming this first gives you clarity about what your system already has and what it still needs.

Installing Git on Windows

Windows does not include Git by default, so you need to install it manually. The most reliable way is to download the official Git installer from git-scm.com and run it on your machine. The installer provides a guided setup wizard that walks you through each configuration option step by step, making the process approachable even if you are new to development tools.

  1. Download the Git installer from the official website at git-scm.com
  2. Run the downloaded installer file (you may need to approve administrator access)
  3. Accept the default settings unless you have a specific reason to change them—the defaults are carefully chosen for most users
  4. Complete the installation and open Git Bash or your preferred terminal to verify the installation with git --version

During installation, you will encounter options for choosing a default text editor, adjusting how Git integrates with your system PATH, and configuring how line endings are handled. If you are unsure about any of these, the default selections work well for most developers and can always be changed later through configuration commands. The installer also gives you the option to use Git from the command line only or to include additional tools like Git Bash, which provides a Unix-style terminal environment on Windows.

Installing Git on macOS

macOS users have a couple of convenient options for installing Git. The simplest method is to install the Xcode Command Line Tools, which includes Git along with other useful developer utilities like compilers and debugging tools. Running the following command in the terminal will prompt you to install them if they are not already present.

xcode-select --install

If you prefer to manage your tools with a package manager, Homebrew is a popular choice on macOS. Many developers appreciate Homebrew because it keeps all their command-line tools organized and easy to update. If Homebrew is already installed on your system, you can install Git with a single command.

brew install git

The Homebrew approach has the added benefit of making it easy to update Git to newer versions later by running brew upgrade git. Either method produces a fully functional Git installation that works identically in the terminal, so you can choose whichever aligns with how you prefer to manage software on your Mac.

Installing Git on Linux

Linux distributions include Git in their official package repositories, which makes installation fast and simple through the terminal. The exact command depends on which distribution and package manager your system uses. This approach leverages your system's built-in package management, ensuring Git integrates cleanly with the rest of your installed software.

For Debian and Ubuntu based systems:

sudo apt update
sudo apt install git

For Fedora and Red Hat based systems:

sudo dnf install git

After the installation completes, run git --version once more to confirm that Git is available and working correctly before moving on to configuration. This verification step is quick but gives you confidence that everything is ready for the next phase.

Setting Up Your Identity

The most important configuration step after installation is setting your name and email address. Git attaches this identity to every commit you create, so it appears in your project history and is visible to collaborators. Skipping this step means your commits will either use incorrect defaults or fail entirely on some systems. Think of this as signing your work—every change you make gets clearly attributed to you.

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

The --global flag applies these settings across all repositories on your system, so you only need to run these commands once. If you work on a specific project that requires a different identity, such as a work project with a professional email, you can override the global setting for that repository alone by running the same commands without the --global flag from inside the project folder. This flexibility is particularly useful for developers who contribute to both personal and professional projects.

Verifying Your Configuration

After setting your identity and any other preferences, it is a good habit to verify that everything is saved correctly. The following command displays all your current Git configuration settings in one place, giving you a complete overview of how Git will behave on your system.

git config --list

Scan the output to confirm your username and email are correct. If you spot a mistake, simply re-run the configuration command with the correct value and it will overwrite the previous entry. You can also check a single setting directly by specifying its key, which is helpful when you only need to confirm one specific value.

git config user.name

Setting the Default Branch Name

Historically, Git named the default branch master when initializing a new repository. Modern conventions have shifted to using main as the default branch name, and most hosting platforms like GitHub now use main as their default as well. Configuring this globally ensures consistency between your local repositories and the platforms you work with, eliminating the need to rename branches after creation.

git config --global init.defaultBranch main

With this in place, every new repository you initialize will automatically start with a branch named main. This small configuration saves you from having to manually rename the default branch later. You can learn more about how branches work and why they matter in Git branching fundamentals.

Choosing a Default Text Editor

Git opens a text editor in certain situations, most commonly when you run git commit without the -m flag, which opens the editor so you can write a detailed commit message. Git also uses the editor when resolving some types of conflicts and during interactive rebase sessions. By default, Git uses the system's default editor, which is often Vim—a powerful editor that can be intimidating and confusing for new users who accidentally find themselves stuck inside it.

Setting a familiar editor upfront avoids that confusion entirely. The following example sets Visual Studio Code as the default editor, which is a popular choice for most developers because of its user-friendly interface and deep Git integration.

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

The --wait flag tells Git to wait until you close the editor window before proceeding. Without it, Git would continue before you finish writing your message, leading to incomplete or missing commit descriptions. You can substitute code with the command for any editor you prefer, such as nano for a simple terminal-based editor, vim if you prefer it, or subl for Sublime Text.

Configuring Line Ending Behavior

Windows and Unix-based systems like macOS and Linux handle line endings in text files differently. Windows uses a carriage return and line feed combination (CRLF), while macOS and Linux use only a line feed (LF). When developers on different systems collaborate on the same project, these differences can cause unnecessary changes to appear in diffs and cause issues with some tools. Every file saved on one system can appear completely changed when viewed on another, making your project history noisy and confusing.

Git can handle line ending conversion automatically if configured correctly. The right setting depends on your operating system.

# Windows: convert line endings automatically on checkout and commit
git config --global core.autocrlf true

# macOS and Linux: normalize line endings on commit without converting on checkout
git config --global core.autocrlf input

Configuring this consistently across your team, ideally enforced through a .gitattributes file in the repository, prevents line ending conflicts from cluttering your project history. This is one of those configurations that you set once and then never think about again, but it quietly prevents a whole category of frustrating problems.

Creating Your First Repository

With Git installed and configured, you are ready to create your first repository. A repository is simply a folder that Git is tracking. The git init command sets up that tracking by creating a hidden .git directory inside your project folder. This hidden folder is where Git stores all its magic—the complete history, configuration, and metadata for your project.

mkdir my-project
cd my-project
git init

From this point, any files you add and commit inside the folder will be part of the repository's history. You can also bring an existing project under version control by running git init inside its folder rather than creating a new one. For a full walkthrough of both initializing and cloning repositories, visit creating and cloning repositories.

Connecting to a Remote Repository

A local repository on your machine is fully functional for personal projects, but working with a team or backing up your code online requires connecting your local repository to a remote one. Remote repositories are hosted on platforms like GitHub, GitLab, or Bitbucket and serve as a shared point through which all collaborators synchronize their work. They also provide a secure off-site backup of your code.

Once your local repository is set up, you can link it to a remote and start pushing and pulling changes. The process of connecting and syncing with remote repositories is covered in full detail in working with remote repositories. This connection is what transforms Git from a solo history tool into a collaboration platform.

Common Setup Mistakes to Avoid

A few small errors during setup can cause confusion later. Being aware of them helps you avoid issues before they appear in your workflow. These are the same mistakes that even experienced developers sometimes make when setting up a new machine.

  • Skipping identity configuration: If you do not set your name and email, commits will carry incorrect or missing author information that cannot be retroactively fixed cleanly in a shared repository. Your contributions become harder to track and attribute.
  • Using the wrong email address: If your email does not match the one linked to your GitHub or GitLab account, your commits will not be associated with your profile on those platforms. Your contributions will appear as anonymous, and you will miss out on the activity tracking that these platforms provide.
  • Not verifying the installation: Proceeding without confirming Git is working can lead to confusing errors later. A quick git --version check takes only a moment and confirms everything is ready.
  • Ignoring line ending settings: On teams with mixed operating systems, inconsistent line ending configuration is a common source of unnecessary diff noise. Setting this early prevents the problem entirely before it ever appears.
  • Using a terminal you are not comfortable with: If you are new to the command line, take a few minutes to get comfortable with basic navigation before diving into Git. Understanding commands like cd, ls, and pwd makes learning Git much smoother.

Conclusion

Getting Git installed and configured correctly takes only a few minutes, but those few minutes pay dividends throughout your entire development career. With your identity set, your preferred editor configured, and your default branch name aligned with modern conventions, your environment is ready to support any Git workflow you encounter. The configuration you have just completed forms the foundation upon which all your future Git work will be built.

The natural next step after setup is learning how Git is actually used day to day. Start with the basic Git workflow to understand how files move through the stages of tracking, staging, and committing. From there, explore Git core concepts and viewing history and changes to build a solid practical foundation before moving into branching, remote collaboration, and more advanced features. Each step builds naturally on the one before, and with your environment properly configured, you can focus entirely on learning rather than troubleshooting setup issues.