How to Install Git on Ubuntu 18.04: The Ultimate Guide

If you are a developer or learning to be one, you might already know how important a version control system is. It helps you keep track of every change that happens to your code. Here, we will be talking about one of the best version control systems available right now — Git.

In this tutorial, you will learn how to install Git on Ubuntu 18.04 to help you write code more effectively.

Why Use Git?

Git can be considered the most popular version control system to date. With it, you can manage your software code by monitoring changes, reverting back to previous versions of your code, or creating new branches for alternative code.

We will list several advantages of using Git, which makes it such an amazing tool, such as:

  • Branching and merging — Git allows you to create a branch of your code when you need to split your work into smaller parts. This will also help you divide your tasks based on the level of importance. What’s great, merging the code back only takes seconds.
  • Small and fast — the tool is lightweight and easy to use because most of the operations can happen locally on your computer.
  • Distributed and secure — as a distributed version control system, you don’t have to worry about data loss. That’s because every user owns a copy of the repository. Moreover, every file is checksummed to prevent corrupt or incorrect data.
  • Staging area — this feature makes Git stand out from the rest. It acts as an intermediate area to review and format every commit of your repository.
  • Open-source and free — Git is a free tool and is maintained by a strong and dedicated community.

What’s great, developers are not the only ones that can benefit from Git. Other fields of work, such as marketing, customer support, and so on are encouraged to implement Git in their projects.

How to Install Git on Ubuntu 18.04

There are two essential steps that you need to follow — installing Git and configuring it on your Linux computer. However, before we begin, pay attention to these prerequisites first.


Make sure that your computer is running on Ubuntu 18.04, codenamed Bionic Beaver. Also, you have to log in to your Linux as root or a user with sudo privileges. If you want to install Git on any other operating system, feel free to read our Git tutorial.

1. Installing Git on Ubuntu

There are two methods to install Git on Ubuntu. We’ll break them one by one and you can choose which one works best for you. Remember, both options require you to use the Linux terminal.

Installing Git With APT

Ubuntu 18.04 already contains Git in default repositories. You can easily install it using the APT package manager.

  1. Firstly,  update the repository by running the following command:
    sudo apt-get update
  2. Note that the version in the repositories might not be the newest one. You can check the available versions with:
    apt-cache policy git

    Here’s an example of the output:

    Installed: (none)
    Candidate: 1:2.17.1-1ubuntu0.4
    Version table:
       1:2.17.1-1ubuntu0.4 500
       500 bionic-updates/main amd64 Packages
       500 bionic-security/main amd64 Packages
       1:2.17.0-1ubuntu1 500
       500 bionic/main amd64 Packages
  3. There are two available versions – 1:2.17.1-1ubuntu0.4 500 and 1:2.17.0-1ubuntu1 500. The candidate version shows which version would be installed. To install Git, simply run:
    sudo apt-get install git

    When the script asks for permission to install Git, press Y.

Installing Git from Github

You can download Git from GitHub to get the latest version of the tool.

  1. With this method, you need an additional Github package before you install Git.
    sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev

    If a confirmation message appears, choose Y.

  2. Once it’s done, visit the Git releases page. Right-click on the tar.gz file of the latest version and copy the link. In this case, we are going to use the latest (at the time writing) v2.23.0 version, so the command should be:
  3. After you have downloaded the file, extract it using:
    tar -zxf v2.23.0.tar.gz
  4. When it’s done, head to the extracted directory:
    cd git-2.23.0/

    Now install git locally by running this command one after the other:

    make prefix=/usr/local all
    make prefix=/usr/local install

    Note, that the installation can take a few minutes to complete.

2. Configuring Git

Once you have successfully installed Git on Ubuntu, you will need to configure it in order to make it work properly.

  1. On the terminal, replace “user_name” with your real username in the following command:
    git config --global "user_name"

    Remember to include the quotation mark.

  2. Now enter your email address instead of “”:
    git config --global ""

Step 3 – List of Basic Git Commands

Here is a list of useful Git commands to help you get started:

Command Explanation
Creating Repository
git clone ssh:// Clone an existing repository
git init Create a new local repository
Working with Local Changes
git status Change files in the working directory
git diff Change to tracked files
git add . Add all changes to your next commit
git add -p Add some changes into your next commit
git commit -a Commit all local changes in tracked files
git commit Commit previously staged changes
git commit -amend Change the last commit
Checking Commit History
git log Show all commits
git log -p Show changes over time for a specific commit
git blame See who changed the commit and when the change happened
Creating Branches and Tags
git branch -av See all existing branches
git checkout Switch to a branch
git branch Create a new branch based on your current branch
git checkout — track <remote/branch> Create a new branch based on a remote branch
git branch -d Delete a local branch
git tag Mark your current commit with a tag
Updating and Publishing
git remote -v List all currently configured remotes
git remote show Show information about a remote
git remote add Add a new remote repository
git fetch Download all changes
git pull branch Download all changes from branches and merge into HEAD
git push Push changes from local to remote
git branch -dr <remote/branch> Delete a branch on the remote
git push — tags Publish your tags
Merging and Rebasing
git merge Merge into current HEAD
git rebase Rebase current HEAD
git rebase — abort Abort a rebase
git rebase — continue Continue a rebase after resolving conflicts
Discarding Changes
git reset — hard HEAD Discard all local changes in your working directory
git checkout HEAD Discard all local changes in a specific file
git revert Revert a specific commit
git reset — hard Reset your HEAD to a previous commit by discarding all changes
git reset Reset your HEAD to a previous commit but preserve all unstaged changes
git reset — keep Reset your HEAD to a previous commit and preserve uncommitted local changes

To see more git commands, use:

git --help


Git is one of the best distributed version control systems in the world. This free tool packs a lot of useful features that help developers manage their code and repositories.

In this tutorial, you have learned how to install Git on Ubuntu 18.04. To summarize, let’s take a look at the steps once again.

  1. Install Git on Ubuntu through APT or GitHub.
  2. Configure your Git by entering your username and email.

Furthermore, we have also added a list of important Git commands that you can use to operate the software.

Don’t forget to leave a comment below if you have any questions!

The author

Elvinas S.

Elvinas is a senior server administrator at Hostinger. He monitors the infrastructure’s well-being and keeps the uptime at a maximum. Besides server management, web development has always been one of his biggest passions.