How to Install and Configure Git on Ubuntu 20.04 (Tutorial)

How to Install and Configure Git on Ubuntu 20.04 (Tutorial). It is worth knowing that the most well known version control system in the world today is Git. So many software projects count on Git for version control. 

In this post, we introduce Git, its features and after that we show you how to install and configure Git on Ubuntu 20.04.

What is GIT?

Image source:Allthings

Currently, GIT is the prominent and widely used control system. Developed as an open source project in 2005, it is a mature and actively maintained environment. Developers usually rely on the GIT version to control and develop several commercial and non commercial projects. DevOps developers consider GIT as a valuable resource.

Truly designed for its speed and simplicity. Moreover Git is fully distributed and has great support that aids parallel development, including supporting hundreds of parallel branches.

Features of GIT

GIT is a main Version Control System today. Moreover, this open source software is easy to handle and perform. What is more, it allows you to work together as a team using the same profiles. Following the features GIT provides to its users:

Distributed System

All in all, Git enables users to perform work on projects worldwide. Altogether, it keeps a central repository accessed by multiple remote collaborators that use a Version Control System. Central Servers sometimes have issues like Data Loss or Data Connectivity. Thanks to GIT, it mirrors the entire repository on every version’s snapshot to tackle this problem. Therefore, if the central server crashes, users acquire copies of repositories from the users who have downloaded the latest snapshot of the project.

Non Linear Development

Users from all across the world can perform operations on the project remotely with the help of GIT. With this tool, users pick up any part of the project and perform the necessary operation, and then further update the operation. Importantly, it is possible only because of the Non Linear development behaviour of the GIT.

Branching

With the help of GIT, users work on a line that runs parallel to the main project files, called branches. With these branches, users make changes to the project without affecting the original version. The version’s master branch constitutes the production quality code. Therefore, users have the availability to test and work on any new features on the branches and further combines them with the master branch.

Compatibility

Certainly, GIT is compatible with every Operating System used these days. Concurrently, it accesses the remote repositories directly that SVNs create. So, users that do not use GIT in the first place can switch to GIT without undergoing the process of copying their files from the repositories of other VCSs into GIT VCS.

Advantages of GIT

Image SourceJavaPoint

Performance

Compared to other Version Control Systems, GIT performs very strongly and reliably. Users commit to new code changes effortlessly and compare and merged with version branches. Consequently, it also optimizes code to perform better. Why? because Git focuses on the content of the file itself rather than the filename as it determines the storage and file type history. The Git repository file format uses several combinations of delta encoding and compression techniques to store metadata and directory content.

Security

Equally, GIT is designed specially to maintain the integrity of source code. The contents of files and the relationship between files and directories, tags, makes, versions, etc., are cryptographically secure using an algorithm called SHA1 that protects the code and changes history from accidental and malicious damage. You can be sure that you have a good history of your source code in Git.

Flexibility

Evidently, GIT offers flexibility to support several kinds of non linear development workflows and its efficiency in handling both small scale and large scale projects and protocols. Specially designed to support tagging activities in domains and save any activity that a user performs as part of the “change” history. Not all VCS support this feature.

Wide Acceptance

Git offers the kind of functionality, features, security, and flexibility that most developers and teams need to develop their projects. Compared to other VCSs, Git is the most widely accepted system due to its usability and universally accepted performance standards.

It is time for the main part of this article about how to Install and Configure Git on Ubuntu 20.04 (Tutorial). Please read on. 

How to Install and Configure Git on Ubuntu 20.04 (Tutorial)

Prerequisites

  • A server running Ubuntu 20.04 operating system.
  • A root user or a user with sudo privileges.

Update Your System

Before starting, you will need to update and upgrade all your system packages to the latest version. Update all of them by running the following command:

				
					apt update -y
apt upgrade -y
				
			

After updating all the system packages, you can proceed to install Git on your server.

Install Git From Ubuntu Repository

The simple and easiest way to install Git is to install it from the Ubuntu default repository. However, these repositories may be older than the newest version currently available.

				
					apt install git -y
				
			

Once the Git is installed, you can verify the Git installation using the following command:

				
					git --version
				
			

You should see the Git version in the following output:

				
					git version 2.36.1
				
			

Install Git From Source

This method is flexible but it will take longer time and you can not manage it via package manager. Before starting, you will need to install some dependencies required to compile the Git. You can install all of them by running the following command:

				
					apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip -y
				
			

Once all the packages are installed, download the latest version of Git from the Git Hub repository:

				
					git clone https://github.com/git/git.git
				
			

Once the download is complete, navigate to the downloaded directory with the following command:

				
					cd git
				
			

Next, start the compilation process with the following command:

				
					make prefix=/usr/local all -j$(nproc)
				
			

Once the Git is compiled, you can install it with the following command:

				
					make prefix=/usr/local install
				
			

After the installation, you can verify the Git version with the following command:

				
					git --version
				
			

You should see the Git version in the following output:

				
					2.38.1
				
			

Once you are done, you can proceed to configure Git.

How to Configure Git

After installing Git, you will need to configure some elements, such as username and email. You can configure it by running the following command:

				
					git config --global user.name "Hitesh Jethva" 
git config --global user.email "hitjethva@gmail.com" 
				
			

The above commands will save all information in the .gitconfig configuration file in your home directory.

You can verify your configuration with the following command:

				
					cat .gitconfig
				
			

You should see the following output:

				
					[user]
	name = Hitesh Jethva
	email = hitjethva@gmail.com
				
			

You can also check the configuration using the following command:

				
					git config --list
				
			

You should see your configuration in the following output:

				
					user.name=Hitesh Jethva
user.email=hitjethva@gmail.com

				
			

How to Use Git

At this point, Git is installed and configured on your server. Now, we will explain how to use Git in the development environment. First, create a new directory in your home directory with the following command:

				
					mkdir gitrepo
				
			

Next, change the directory to the gitrepo using the following command:

				
					cd gitrepo
				
			

Next, initiate the Git by running the following command:

				
					git init
				
			

Next, add your Git repository with the following command:

				
					git remote add origin  https://github.com/hitjethva/vue-blog
				
			

After that, please create a new file with the following command:

				
					touch file.txt
				
			

Then, add this file to the Git repository with the following command:

				
					git add file.txt
				
			

Following step is to commit the file with your message with the following command:

				
					git commit -m 'added file.txt'
				
			

Here, in this step, push the commit to the repository with the following command:

				
					git push origin master
				
			

You will be asked to provide your GitHub username and password as shown below:

				
					Username for 'https://github.com': hitjethva
Password for 'https://hitjethva@github.com': *******
				
			

After the successful authentication, your file will be added to your GitHub repository.

Thank you for reading How to Install and Configure Git on Ubuntu 20.04 (Tutorial). We will conclude. 

How to Install and Configure Git on Ubuntu 20.04 (Tutorial) Conclusion

In this post, we explained how to install Git using two methods on Ubuntu 20.04. We also configure the Git, clone the remote repository then add the local file to the GitHub repository. You can now implement Git server in your development environment and start managing all codes from the central location.

Using Git, you can also run tests in the project without affecting the original version. Git tracks changes that you make to files. It creates a possibility to roll back to a particular version if necessary. Have a look at its features and benefits to learn more about Git.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x