How to Install Git
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:
git --versiongit version 2.53.0If you see a version number, Git is installed. The line can look slightly different on your computer:
| You see | It means |
|---|---|
git version 2.53.0 | Git is installed, on macOS or Linux |
git version 2.53.0.windows.1 | Git 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: git | Git is not installed (macOS or Linux) |
'git' is not recognized as an internal or external command | Git 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.
winget install --id Git.Git -e --source wingetbrew install gitsudo apt update
sudo apt install gitsudo dnf install gitAfter 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:
- With the installer: go to git-scm.com/downloads, download the Windows installer and run it.
- With winget: run the command from the Windows tab above in PowerShell.
wingetis 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 about | Choose | Why |
|---|---|---|
| The default editor | An editor you already know, such as Visual Studio Code or Notepad | The preselected choice is Vim, which confuses most beginners |
| The name of the initial branch | "Override the default branch name" with main | main 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:
- Apple's Git. The first time you type
gitin Terminal, macOS offers to install the "command line developer tools". You can also start that withxcode-select --install. It works, but Apple's Git is usually several versions behind. - Homebrew. If you use the Homebrew package manager,
brew install gitgives you the current version, andbrew upgrade gitkeeps it current. This is the choice we recommend.
Linux
Git is in the package manager of every Linux distribution:
| Distribution | Command |
|---|---|
| Ubuntu, Debian, Linux Mint | sudo apt install git |
| Fedora, RHEL, CentOS Stream | sudo dnf install git |
| Arch Linux, Manjaro | sudo pacman -S git |
| openSUSE | sudo zypper install git |
sudo runs the command as an administrator, so it asks for your password.
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 switchandgit 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:
git update-git-for-windowsbrew upgrade gitsudo apt update
sudo apt install gitWhich Terminal to Use
You type Git commands in a terminal: a window where you type a command, press Enter, and read the answer.
| System | Terminal | Notes |
|---|---|---|
| Windows | Git Bash | Installed with Git. Understands ls, echo, mkdir and cat exactly as this course writes them. Use this one while you learn. |
| Windows | PowerShell or Windows Terminal | All git commands work the same. A few helper commands, such as creating a file with echo, behave differently. |
| macOS | Terminal | Already installed |
| Linux | Your distribution's terminal | Already 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:
| Way | Examples | Good for |
|---|---|---|
| Terminal | Git Bash, Terminal | Learning, because you see every command and every message. Works the same on every computer and server. |
| Inside your editor | Visual Studio Code, IntelliJ IDEA, Eclipse | Everyday work: staging files, committing and comparing versions next to your code |
| GUI apps (graphical programs with windows and buttons) | GitHub Desktop, Sourcetree, GitKraken | Looking 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
git --version
git -vgit version 2.53.0
git version 2.53.0Both 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.
Key Takeaways
Quick reference
| Command | It is used to |
|---|---|
git --version | Show the installed Git version |
winget install --id Git.Git -e --source winget | Install Git on Windows |
brew install git | Install Git on macOS with Homebrew |
sudo apt install git | Install Git on Ubuntu or Debian |
sudo dnf install git | Install Git on Fedora |
git update-git-for-windows | Update Git on Windows |
Was this tutorial helpful?