Installing Git
Git is a program that allows you to keep track of changes to your coding projects (giving you the confidence you need to update and experiment without fear of losing your existing working code) and to share your code with others (allowing you to collaborate on projects). It is a powerful tool for any programmer, whether working alone or with others.
Though it may look overwhelming (and at times even magical), Git works like any other program you use in your day-to-day. This means you must first install Git on your system in order to take advantage of its powerful tools.
Many Linux and MacOS systems come with Git pre-installed, while Windows does not. We recommend you check to see if you have Git installed already!
To know if you have Git installed, you can look at the list of installed programs or try running a Git command in your terminal, according to your operating system.
Windows does not include Git by default, which means that unless you installed it in the past, it’s unlikely to be installed on your computer. You can check by going to your Start Menu, then Apps (Programs), and looking for Git. If it isn’t in your apps list, see Installing Git for instructions.
If you’re familiar with the command line, you can also check by opening PowerShell and running:
git version
git version 2.28.0
Git often comes pre-installed on MacOS or with other development tools, like Xcode. To check for Git, open your terminal and run:
git version
git version 2.28.0
Git often comes pre-installed on Linux distros. To check for Git, open your terminal and run:
git version
git version 2.28.0
The output of this command will be different according to whether Git is installed on your machine.
If Git is not already installed, you will receive an error message telling
you that the git
command is not recognized and that it needs to be installed.
If you already have Git installed, your terminal will respond with your current version of Git. For example:
git version
git version 2.28.0
Compare the output to the lowest recommended version noted above! If your version is lower, follow the Installing Git instructions to update your installed version.
How you install Git will depend on your operating system:
-
Go to Git’s website for Windows.
-
Choose the link under Standalone Installer for your system.
-
Once the installer downloads, navigate to where you saved it and double-click the icon to open the installer.
-
Select Destination Location: Install Git in the default location.
-
Select Components: You can proceed with the default selections.
-
Select Start Menu Folder: Keep the default.
-
Choosing the default editor used by Git: This setting allows you to chose what program Git uses for editing text (like commit messages). You can leave the default setting (Vim) or update to your favorite text editor from the dropdown.
-
Adjusting the name of the initial branch in new repositories: The default option is to name the initial branch “master”. Recently, there’s been an effort to move away from this terminology. We recommend you select the bottom option to override this default and type “main” into the box that opens.
-
Adjusting your PATH environment: If it isn’t already selected, choose the recommended setting (Git from the command line and also from 3rd-party software). This will allow you to integrate Git into your coding editors and other tools, which will be very useful as your coding journey progresses.
-
Choosing the SSH executable: Keep the default.
-
Configuring the line ending conversions: Windows marks line breaks in a text file differently than Unix-based operating systems (MacOS, Linux). Because of that, this setting can impact how “nice” your commits play in cross-platform projects. Keep the default setting for now.
-
Configuring the terminal emulator to use with Git Bash: Keep the default option.
-
Choose the default behavior of
git pull
: Update this to Only ever fast-forward. -
Continue through any remaining screens with the default options.
To install or update Git on MacOS, visit Git’s website for MacOS and choose your favorite method of installation. We recommend using homebrew to install on MacOS.
If you run into issues with installation (for example, if the installer is failing, you’re receiving other errors, your system is holding onto the older version, etc.), you may need to uninstall Git using your terminal (command line).
-
Open your terminal.
-
Run
which git
in your terminal.Terminal window which git# the terminal returns the path where Git is installed. The default is listed below./usr/local/bin/git -
Run the command below to delete the folder at the path returned by
which git
and uninstall Git.Terminal window sudo rm -rf $(which git) -
Follow the instructions above to reinstall a newer version of Git.
To install or update Git on Debian/Ubuntu, open your terminal and run:
sudo apt-get install git
You can find a list of commands for different distributions on Git’s website for Linux.
🎉 Congratulations! You’ve installed Git! 🎉