24/7/365 Support

Installing Git on Ubuntu server

This recipe covers the installation of Git binaries on the Ubuntu server. As always, we will install the latest available Git package.

Getting ready

You will need access to a root account or an account with sudo privileges.

How to do it…

Git maintains a separate repository of the latest binaries on Launchpad. We will use PPA for this repository,to install the latest Git version:

Add PPA to the Ubuntu installation source:

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

Update the apt repository cache:

$ sudo apt-get update

Now, install Git with a simple apt-get install git command:

$ sudo apt-get install git -y

Once installation completes, you can check the Git version with the following command. You can cross check the version with the official Git download page:

$ git version

Now introduce yourself to Git by providing your name and email address. Git will add this information to every commit message made by you:

$ git config --global user.name "Your Name"

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

You can cross-check the configuration by using the --list parameter to git config:

$ git config --list

Use git help to get a list of the basic daily use commands:

$ git help

How it works…

Here, we have the installed the latest Git version from the repository maintained by Git developers. The Ubuntu default package repository contains the Git package, but often it is not updated. Ubuntu 14.04 still provides Git version 1.9.1.

Once the Git packages are installed, you need to identify yourself to Git. This information is used to tag the commits created by you. We have globally set the username and email with the git config command. Now, whenever you create a new commit in any repository on this system, the commit will get tagged with your username and email. This helps in tracking who did what, especially when you are working in a large group. You can get a list of configuration settings with the command git config --list, and the output should look something like the following:

$ git config --list

user.name=yourname

user.email=youremail@example.com

If you execute the same command from within a repository directory, the list will show some extra settings specific to that repository:

~/sample-repo$ git config --list

user.name=yourname

user.email=youremail@example.com

core.repositoryformatversion=0

core.filemode=true

core.bare=false

core.logallrefupdates=true

Now, if you are not already familiar with Git, you can make use of the git help command to get documentation and manual pages. The default help menu lists commonly used commands with a short description. You can get a list of all available commands with the same git help command and a flag, -a.

$ git help -a

Additionally, the installation contains some guides or manual pages to help you get started with Git. To get a list of the available guides, use:

$ git help -g

The common Git guides are as follows:

attributes: Defines attributes per path

glossary: A Git glossary

ignore: Specifies intentionally untracked files to ignore

To open a particular guide, use the git help guidename or the man git[guidename] command:

$ git help everyday # or man giteveryday

There's more…

Git has become a mainstream version control system, especially after the rise of the social coding site GitHub. There are other well-known version control systems available, such as Subversion and Mercurial. Facebook uses a modified version of Mercurial for their internal code hosting. Bazaar is another distributed version control system sponsored and developed by Canonical, the force behind Ubuntu. Bazaar provides tight integration with Launchpad, a collaborative development platform by Canonical.

You can get more details about Bazaar on their official page at http://bazaar.canonical.com/en/ .

See also

You can read more by following these links:

Git basics: https://git-scm.com/book/en/v2/Getting-Started-Git-Basics

Git book: https://git-scm.com/book/en/v2

Check out the Git interactive tutorial at: https://try.github.io and http://git.rocks/

Launchpad: https://launchpad.net/

Help Category:

What Our Clients Say