VPS

How to Install Git on Ubuntu 14.04

Introduction

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:

git:
  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.

CommandExplanation
Creating Repository
git clone ssh://username@somedomain.com/repo.gitClone an existing repository
git initCreate a new local repository
Working with Local Changes
git statusChanged files in working directory
git diffChanges to tracked files
git add .Add all changes to your next commit
git add -pAdd some changes in to your next commit
git commit -aCommit all local changes in tracked files
git commitCommit previously staged changes
git commit -amendChange the last commit
Checking Commit History
git logShow all commits
git log -pShow changes over time for specific
git blameSee who changed what and when in
Creating Branches and Tags
git branch -avSee all existing branches
git checkoutSwitch to branch
git branchCreate a new branch based on your current branch
git checkout — track <remote/branch>Create a new branch based on remote branch
git branch -dDelete a local branch
git tagMark your current commit with a tag
Updating and Publishing
git remote -vList all currently configured remotes
git remote showShow information about a remote
git remote addAdd new remote repository
git fetchDownload all changes from
git pull branchDownload all changes from and merge into HEAD
git pushPush changes from local to remote
git branch -dr <remote/branch>Delete a branch on the remote
git push — tagsPublish your tags
Merging and Rebasing
git mergeMerge into current HEAD
git rebaseRebase current HEAD onto
git rebase — abortAbort a rebase
git rebase — continueContinue a rebase after resolving conflicts
Discarding Changes
git reset — hard HEADDiscard all local changes in your working directory
git checkout HEADDiscard all local changes in a specific file
git revertRevert a specific commit
git reset — hardReset your HEAD to a previous commit by discarding all changes since then
git resetReset your HEAD to a previous commit but preserve all unstaged changes
git reset — keepReset your HEAD to a previous commit and preserve uncommitted local changes

To see more git commands use:

git --help

Conclusion

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.

Add Comment

Click here to post a comment

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

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

Close