Install Git Verion Control on Linux (Debian/Ubuntu/Fedora/ArchLinux)

Git is a free, fast and powerful distributed version control system (DVCS). This guide will show you how to install Git On Linux, including Debian, Ubuntu, Fedora, Archlinux and there derivatives. And also explains the initial setup and create your first Git project.

Install Git

Debian/Ubuntu

sudo apt-get install git

Fedora:

sudo dnf install git

CentOS/Redhat:

sudo yum install git

Arch Linux

sudo pacman -S git

Check your Git version by typing:

git --version

The Initial Setup

User-Specific Configuration

After you install Git, we need to add an username and email address. Git will automatically embed this information whenever we commit our changes to Git repository. This can be done with the following command.

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Then you can check your settings like below.

git config -l

The –global option in the above command specify that your configuration will be stored in .gitconfig file in your home directory and is only valid for yourself. You can use your text editor to edit this file and change your configurations.

System-Wide Configuration

If you want every user on the system to have this same configuration, then you must pass the –system option instead of –global option.

sudo git config --system user.name "Your Name"
sudo git config --system user.email "[email protected]"

Because the system-wide configuration file resides in /etc/gitconfig, you need sudo privilege to do so.

The user specific configuration overrides the system wide configuration. So if you set these values using –system option, but another user set his/her own configuration using –global option, then the user will have his/her own username and email address.

Project Specific Configuration

If you want to use a different username and email address in a project, then cd to your project directory and issue the below command:

git config --local user.name "Your name"
git config --local user.email "[email protected]"

In this situation, your project’s configuration is stored in .git/config file under your project directory.

Create Your Very First Git Project

Navigate to a directory which you want to keep track of.  And type the below command:

git init

The init command will create a .git directory and initialize a repository in the current directory.  Repository means a Git project. They are the same thing.

If your directory is not empty, then you may want to add your subdirectories and files to commit to the repository. This can done with the below commands

git add .
git commit -m "Initial Commit"

The period in the first command means current directory. Once the first command is completed, all contents found in the current directory will be staged for the next commit. The seconed command will save your files or changes to your repository.

Getting Help

If you ever need to get help, just type in git help. Pretty easy. If you need help on a specific git command such as add, then type in git help add.

Rate this tutorial
[Total: 2 Average: 4.5]

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here