How to Install and Set-up Git
Git is a version control system designed to keep track of source code changes. It can be used by a lone developer to keep a history of project versions or to help a team of developers collaborate together. Before you can use Git it will need to be installed.
In this tutorial, we will learn how to install Git on your system and set up your user details so others will know you have made code changes.
Check if Git is installed
First, open a terminal window and type the following command to lookup your Git version.
git --version
git version 2.7.4
If a Git version number is returned, awesome! You already have Git installed and you can move on to the setting up section. If you get a command not found error, you will need to install Git.
git: command not found
How to Install Git on Linux
Depending on your variant of Linux you will need to install Git using either the yum
or apt
package manager. Let's go through this process for the most popular Linux distributions.
Installing Git on Ubuntu or Debian
For Ubuntu or Debian use the apt package manager. Begin by updating apt
then installing Git; you will have to run these commands in sudo mode.
sudo apt update
sudo apt install git
Installing Git on CentOS or Fedora
If you're using CentoOS or Fedora, use the yum
package manager. Begin by updating the yum software then installing Git.
sudo yum update
sudo yum install git
Installing Git on macOS
macOS should have Git preinstalled if it isn't type git
into the terminal and you should be prompted to install it. if for some reason you don't get a prompt a good option would be to install it using the Homebrew package manager for macOS like this:
brew install git
Installing Git on Windows
The best option for installing Git on Windows is to download the build from the official Git website (here is the download page for Windows).
Setting up Git
Once the installation is complete, the next step is to add your details so that changes to repositories made by you will show your name. To do this we will need to edit the user name and email inside your Git configuration file.
git config --global user.name "John"
git config --global user.email "[email protected]"
Replace the details inside the double quotes to your desired values. To test your configuration is indeed set use the config --list
command:
git config --list
You should see something like this:
user.name=John
[email protected]
Conclusion
That's it! Git is now configured and ready to use on your machine.