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.
sudo apt-get install git
sudo dnf install git
sudo yum install git
sudo pacman -S git
Check your Git version by typing:
The Initial Setup
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.
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:
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.
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.