How to Install Git

Updated · 9 min read
easyGit 2.53gitinstallsetupwindowsmacoslinux

Before Srihitha can join the Fee Tracker project, she needs Git on her laptop. Git is a small program, the installation takes a few minutes, and it is free on every operating system.

In this lesson, you will check whether Git is already on your computer, install or update it, and choose where you will type your Git commands.

Check Whether Git Is Already Installed

Many computers already have Git. Open a terminal and ask Git for its version:

Terminal
git --version
Output
git version 2.53.0

If you see a version number, Git is installed. The line can look slightly different on your computer:

You seeIt means
git version 2.53.0Git is installed, on macOS or Linux
git version 2.53.0.windows.1Git for Windows is installed
git version 2.39.5 (Apple Git-154)The Git that Apple ships with its developer tools (your numbers may differ)
command not found: gitGit is not installed (macOS or Linux)
'git' is not recognized as an internal or external commandGit is not installed, or the terminal can't find it (Windows)

Install Git

Pick your operating system. The command installs the newest Git that your system's package manager offers. The sections below explain each one, and they also show how to install with a normal installer if you prefer that.

Shell
winget install --id Git.Git -e --source winget

After the installation, close the terminal, open a new one, and run git --version again.

Windows

Git for Windows is the official build. You can install it in two ways:

  1. With the installer: go to git-scm.com/downloads, download the Windows installer and run it.
  2. With winget: run the command from the Windows tab above in PowerShell. winget is the package manager that comes with Windows 10 and 11.

The installer asks many questions. The default answer is right for almost all of them. These four are worth a careful look:

The installer asks aboutChooseWhy
The default editorAn editor you already know, such as Visual Studio Code or NotepadThe preselected choice is Vim, which confuses most beginners
The name of the initial branch"Override the default branch name" with mainmain is the name used by GitHub, GitLab, Bitbucket and this course
The PATH environment"Git from the command line and also from 3rd-party software"So that PowerShell and your editor can find Git
Line endings"Checkout Windows-style, commit Unix-style line endings"Keeps files tidy when teammates use macOS or Linux

Git for Windows also installs Git Bash, a terminal that understands the same commands as macOS and Linux. You will read more about it below.

macOS

macOS has two common sources of Git:

  1. Apple's Git. The first time you type git in Terminal, macOS offers to install the "command line developer tools". You can also start that with xcode-select --install. It works, but Apple's Git is usually several versions behind.
  2. Homebrew. If you use the Homebrew package manager, brew install git gives you the current version, and brew upgrade git keeps it current. This is the choice we recommend.

Linux

Git is in the package manager of every Linux distribution:

DistributionCommand
Ubuntu, Debian, Linux Mintsudo apt install git
Fedora, RHEL, CentOS Streamsudo dnf install git
Arch Linux, Manjarosudo pacman -S git
openSUSEsudo zypper install git

sudo runs the command as an administrator, so it asks for your password.

One check after installing on any system

Which Version Do You Need

This course was written and checked with Git 2.53. You don't need exactly that version, but newer is better:

  • Git 2.23 or newer is needed for git switch and git restore, the modern commands this course teaches first.
  • A few lessons use something newer. When they do, the lesson names the version.

To update Git later, use the same tool that installed it:

Shell
git update-git-for-windows

Which Terminal to Use

You type Git commands in a terminal: a window where you type a command, press Enter, and read the answer.

SystemTerminalNotes
WindowsGit BashInstalled with Git. Understands ls, echo, mkdir and cat exactly as this course writes them. Use this one while you learn.
WindowsPowerShell or Windows TerminalAll git commands work the same. A few helper commands, such as creating a file with echo, behave differently.
macOSTerminalAlready installed
LinuxYour distribution's terminalAlready installed

The git commands themselves are identical everywhere. Where the commands around them differ between systems, the lessons show both in tabs.

Terminal, Editor or GUI

Typing commands is not the only way to use Git. There are three:

WayExamplesGood for
TerminalGit Bash, TerminalLearning, because you see every command and every message. Works the same on every computer and server.
Inside your editorVisual Studio Code, IntelliJ IDEA, EclipseEveryday work: staging files, committing and comparing versions next to your code
GUI apps (graphical programs with windows and buttons)GitHub Desktop, Sourcetree, GitKrakenLooking at a busy history as a picture

Every button in an editor or a GUI app runs a Git command for you. If you know the commands, you understand what each button does, you can read its error messages, and you can fix problems that the buttons can't.

That is why this course uses the terminal. A later lesson, "Git in VS Code and IntelliJ IDEA", shows the same work in Visual Studio Code and IntelliJ IDEA.

Common Mistakes

Not reopening the terminal after installing. A terminal that was open during the installation doesn't know about the new program and still says that git is not recognized. Close it and open a new one.

Installing GitHub Desktop and expecting the git command to work. GitHub Desktop is a GUI app. It carries its own private copy of Git, which the terminal can't see. Install Git itself as shown above.

Staying on a very old Git. A Git from 2018 doesn't know git switch or git restore, so commands from this course fail with "is not a git command". Check with git --version and update.

Using the old Command Prompt on Windows. The git commands work there, but ls, cat and rm don't, and the lessons use them to create and inspect files. Use Git Bash.

Choosing Vim as the editor by accident. If Git ever opens a screen you can't type in or leave, you are in Vim. Type :q! and press Enter to leave it. The next lesson, "Git Config: Setting Up Git", shows how to pick a different editor.

Practice

Challenge: confirm your installation. Open a new terminal and ask Git for its version. Then try the short form of the same question, git -v.

What does Git print? Git added -v as a short form of --version in 2022. Decide what each command prints on Git 2.53 before you open the solution.

Show solution
Terminal
git --version
git -v
Output
git version 2.53.0
git version 2.53.0

Both print the same line. If git -v shows a usage message on your computer instead, your Git is from before 2022 and it is time to update.

Quick check: Installing Git

4 questions
1Which command tells you whether Git is installed, and which version?
2You installed Git on Windows, but the terminal you had open still says git is not recognized. What do you try first?
3Which Windows terminal understands ls, cat and echo the way this course writes them?
4What happens when you click "Commit" in Visual Studio Code?

Key Takeaways

Quick reference

CommandIt is used to
git --versionShow the installed Git version
winget install --id Git.Git -e --source wingetInstall Git on Windows
brew install gitInstall Git on macOS with Homebrew
sudo apt install gitInstall Git on Ubuntu or Debian
sudo dnf install gitInstall Git on Fedora
git update-git-for-windowsUpdate Git on Windows

Was this tutorial helpful?

Lesson 5 of 106