What is “version control”, and why should you care? Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.
One of the most popular version control systems currently available is Git. Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
In this guide, we will demonstrate how to install and configure Git on an Ubuntu 18.04 server.
Following things are required:
- a non-root user with sudo privileges
There are two main ways to install Git, shown in steps 1.1 and 1.2 below. You only need to follow one of the steps, not both.
Ubuntu’s default repositories provide you with a fast method to install Git. The version you install via these repositories may be older than the newest version currently available from the official repository.
First, use apt to update your local package index. With the update complete, you can download and install Git:
sudo apt update sudo apt install git
You can check Git version by running the following command:
A more flexible method of installing Git is to compile the software from source. This takes longer and will not be maintained through your package manager, but it will allow you to download the latest release and will give you some control over the options you include if you wish to customize.
Before you begin, you need to install the software dependecies.
sudo apt-get install make autoconf libcurl4-gnutls-dev gettext gcc zlib1g-dev unzip
After you have installed the necessary dependencies, you can go ahead and get the version of Git you want by visiting the Git project’s mirror on GitHub:
From here, be sure that you are on the
master branch. Click on the Tags link and select your desired Git version.
Move into the
tmp directory to download temporary files and you can use the
wget command to install the copied zip file link.
cd /tmp wget -O git.zip https://github.com/git/git/archive/master.zip
Unzip the file and move into the resulting directory by typing:
unzip git.zip cd git-*
Now, you can make the package and install it:
make configure ./configure --prefix=/usr --without-tcltk make all sudo make install
You can check Git installed version by typing
git --version .
You can install the git
man pages by typing:
cd .. git clone git://github.com/gitster/git-manpages.git cd - sudo make quick-install-man
Now that you have Git installed, you should configure it so that the generated commit messages will contain your correct information.
This can be achieved by using the git config command. Specifically, we need to provide our name and email address because Git embeds this information into each commit we do. We can go ahead and add this information by typing:
git config --global user.name "Your Name" git config --global user.email "firstname.lastname@example.org"
We can see all of the configuration items:
git config --list
The information you enter is stored in your Git configuration file, which you can optionally edit by hand with a text editor like this:
With Git installed and set up on your local machine, you are now ready to use Git for version control of your own software projects as well as contribute to open-source projects that are open to the public.