How to Install Git on Ubuntu 14.04

Git is one of the most popular versions control system. You can manage your software code by monitoring changes, reverting back to previous versions of your code or create new branches for alternative code that you will be able to merge with your main code later on. This guide will help you install Git on Ubuntu 14.04.

What you’ll need

Before you begin this guide you’ll need the following:

  • Access to Ubuntu 14.04 terminal

Step 1 — Installing Git on Ubuntu

Option 1 – Installing Git With Apt

Ubuntu 14.04 already contains Git in default repositories. You can easily install it using the apt package manager. Firstly update it by running the following command:

sudo apt-get update

Note that version in the repositories might not be the newest one, you can check available versions with:

apt-cache policy git

An example output would be:

  Installed: (none)
  Candidate: 1:1.9.1-1ubuntu0.3
  Version table:
     1:1.9.1-1ubuntu0.3 0
        500 http://archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
     1:1.9.1-1 0
        500 http://archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

There are 2 available versions – 1:1.9.1-1ubuntu0.3 0 and 1:1.9.1-1 0 . Candidate version shows which version would be installed. To install git run:

sudo apt-get install git

Running this command will install git on your system.

Option 2 – Installing Git from GitHub

If you need the most recent version of git then you can install it from GitHub. Before you install git you need additional packages for it:

sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev

Now visit this link and download the version you want to install.

Git download

In our example, we are going to use v2.11.0 version so it can be extracted using:

tar -zxf v2.11.0.tar.gz

However, you would need to use filename that you have downloaded instead of v2.11.0.tar.gz. Enter extracted directory:

cd git-2.11.0/

Now install git locally by running:

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

Step 2 — Configuring Git

Once you have successfully installed Git you will need to configure it. Set your username instead of user_name in the following command:

git config --global user.name "user_name"

Now enter your email address instead of email@domain.com.

git config --global user.email "email@domain.com"

Step 3 – List of Basic Git Commands

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

Command Explanation
Creating Repository
git clone ssh://username@somedomain.com/repo.git Clone an existing repository
git init Create a new local repository
Working with Local Changes
git status Changed files in working directory
git diff Changes to tracked files
git add . Add all changes to your next commit
git add -p Add some changes in to 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 specific
git blame See who changed what and when in
Creating Branches and Tags
git branch -av See all existing branches
git checkout Switch to branch
git branch Create a new branch based on your current branch
git checkout — track <remote/branch> Create a new branch based on 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 new remote repository
git fetch Download all changes from
git pull branch Download all changes from 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 onto
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 since then
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


Using this tutorial you have learned how to install Git on Ubuntu 14.04. You have also learned basic Git configuration and commands. You can now manage your code more effectively by creating branches, reverting changes and keeping track of your code.

About 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.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in VPS
How to Create Apache Virtual Hosts on CentOS 7