How to Upgrade GIT on Ubuntu 20.04 LTS

Ubuntu 20.04 Focal Fossa comes shipped with GIT in their principal repository; however, with Ubuntu 20.04 being an LTS system, the software packages are designed to be stable and do not typically have to include new releases with upgraded features that could break stability. Ubuntu will only ship security updates for the current LTS version of Git.

Sometimes, the issue with LTS systems is that software packages fall far behind with non-security bugs occurring. Luckily with Ubuntu, we can add custom PPA’s from developers of such trustworthy software and typically are the ones to address security issues in the first place. Hence, in the case of Git, the chances of your system being vulnerable are very slim, considering the benefits of updating for new features improvements to non-security-related issues and bugs.

In the following tutorial, you will learn how to upgrade to the latest GIT on Ubuntu 20.04 LTS Focal Fossa using the GIT PPA from Launchpad using the command line terminal.

What is Git?

GIT is for developers that need a pretty straightforward version control system. Most software is collaborative efforts and sometimes can have hundreds of people with commits working on software development projects. It’s essential to track these commits customarily done in branches in most projects before merging into the master for release. It is easy to review and track down any incorrect commits and revert, leading to a much easier development if anything goes wrong.

Check Git Version

First, check to see what version of git you are currently running with the following command.

git --version

If you have GIT installed, you do not need to remove it after installing the PPA, and you can update it or install it fresh if you do not have it on your Ubuntu system.

Install Custom PPA: GIT-CORE/PPA

Next, we will add a custom PPA GIT Core maintained by the Ubuntu Git Mainters team for the latest stable version.

sudo add-apt-repository ppa:git-core/ppa -y

This PPA has the most up-to-date packages for GIT, so you should always be up-to-date with the latest stable versions in the future.

Finalize GIT Install or Update/Upgrade

In the final part, run the following command:

sudo apt update

If you have Git installed, you should see two new packages to upgrade.

Next, use the following command to upgrade.

sudo apt upgrade -y

If you need to install Git as you do not have it installed, do the following command:

sudo apt install git -y

Once done, check the version to see your new Git version.

git --version

With the tutorial, the original version was v2.25.1, and the new version was 2.31.1 at the time of the creation of the tutorial. Furthermore, any further updates will be automatically downloaded and installed with the new PPA repository added.

GIT Configuration & Setup

The following parts will cover some typical setups and commands that are used daily by users of GIT.

GIT Add user

After installation, you will need to set up standard settings such as names and e-mails, mainly around git commit messages. This is pretty straightforward, as the tutorial will explain below.

The first step is to provide your name that will be set Globally.

git config --global "YOUR NAME"

Next, select your e-mail that will appear in the commit message history log.

git config --global "YOUR EMAIL"

GIT Create Directory

First, create the directory for users who want to make a new directory strictly for GIT.

mkdir example-directory -p

Next, navigate to the directory.

cd example-directory -p

The next task is to use the initialization command, and this will create a hidden .git directory to store the configuration, history, and so on.

git init

You will see a terminal output stating the status of the directory being initialized, and you can additionally see the content using the following command.

ls -a .git

Print GIT CONFIG Details

To confirm GIT config users and details, use the config –list command.

git config --list

Unless specified, Git stores details in the ~/.gitconfig file. You can review what is currently stored by using the cat command.

cat ~/.gitconfig

Note that using the sudo command with the git config command will set two separate user names and e-mails.

Store GIT Credentials

For users who want to keep authorization details stored, you can enable the credential helper cache using the following.

git config --global credential.helper cache

If you must use credential helper, it is advised to cache only for a limited time for increased security. For example, you will be working today using GIT for 1 to 4 hours but won’t be touching it for maybe a few weeks, then set the expiry for 5 hours as follows.

git config --global credential.helper "cache --timeout=18000"

After 5 hours, the credentials will be deleted, securing your GIT.

Check Directory GIT Status

To view the status of a GIT repository, you can use the following git status command.

git status

While the above command helps with giving a status of the GIT, you can additionally list all git commands and sub.

Connect Remote GIT Repository

Users that need to work with GIT remotes to sync and download/upload changes, you will need to link the GIT. This can be done using the git remote command as follows.

git remote add origin remote-repository-link

Commit GIT Changes

When you have completed changes in your GIT directory and would like to SYNC it to push to the remote repository, use the following git commit command.

git commit -m "git message changelog"

Note that the -m “git message change” is the message that appears in the changelog.

Push GIT Changes

To push or send changes to the remote repository to SYNC in both versions, use the following git push command.

git push origin master

Pull GIT Changes

Alternatively, to pull or get changes from the remote repository to SYNC in both versions, use the following git push command.

git pull origin master

How to Update/Upgrade GIT

For updates to GIT, they will be included with your standard system packages as you installed git-core with the APT package manager. Use the following command to update and upgrade.

sudo apt update && sudo apt upgrade

How to Remove (Uninstall) GIT

For users that no longer want GIT installed or would instead roll back to the default packages present in Ubuntu’s repository, first use the following command to remove git.

sudo apt autoremove git -y

Next, remove the PPA.

sudo add-apt-repository --remove ppa:git-core/ppa -y

Comments and Conclusion

Git is a fantastic piece of software for software developers and even sys admins. Web server owners can track changes on specific directories when developing their servers or website, and the ability to quickly revert should not be looked over. Git is not the most accessible software to work. However, it works well for what it is designed for.


Like to get automatic updates? Follow us on one of our social media accounts!