How To Install Git on Debian 7

Published on October 29, 2013

Adam LaGreca

How To Install Git on Debian 7

What the Red Means

Lucky for you, the majority of code in this tutorial can be copy and pasted! The lines that you will actually need to enter or customize will be red in this tutorial.

About Git

Git is a version control system distributed under the terms of the GNU General Public License v.2 since its release in 2005. It allows for non-linear development of projects and can handle large amounts of data effectively. This is the case because every working directory in Git is a full-fledged repository with complete history and tracking capabilities that are non-dependent on network access or a central server.

The advantages of using Git stem from the way the program stores data—unlike other VCS’s, it is best to think of the storage process as a set of snapshots of a mini filesystem primarily on your local disk, maximizing efficiency and allowing for powerful tools to be built on top of it.

Install Git with Apt-Get

Install Git with apt-get in one command!

sudo apt-get install git-core

The end! Just kidding, you still need to configure Git.

If you wish to download the most recent version of Git from the source, follow the next step. Otherwise, skip down to setup.

Install Git from the Source

Run "apt-get update" to make sure that you download the most recent packages to your VPS. After that is successful, we are going to download all of the required dependencies (line 1). Finally, only after following the two preceding steps, may you move on to installing the latest version of Git via the google code page (line 2).

Line 1

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

Line 2

wget https://github.com/git/git/archive/v1.9.4.tar.gz

After it downloads, untar the file and switch into that directory:

tar -zxf v1.9.4.tar.gz
cd git-1.9.4

Global Install

This is a slightly different and more complex process. But do not worry, weary traveler! If you wish to perform a global install it's a two-step process: 1) Install it once as yourself and 2) Install it once as root.

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

How to Setup Git

After Git is installed you need to copy your username and email in the gitconfig file. Using the nano command "sudo nano ~/.gitconfig" will open a completely blank page, as you have just done a fresh install. Insert the necessary information with the following commands:

git config --global user.name "NewUser"
git config --global user.email newuser@example.com

You can see all of your settings with this command:

git config --list

See Also

To learn more about using git, visit the link, How To Use Git Effectively.

By Adam LaGreca

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us

About the authors
Default avatar
Adam LaGreca


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

This comment has been deleted

    I’ve installed Git once with Apt-get then got the “bad config file line 1 in /root/.gitconfig” error then I tried installing with source, the result was the same, moved on to the “Global install” section, But again i’m getting the “bad config file line 1 in /root/.gitconfig” error. what am I missing?

    Kamal Nasser
    DigitalOcean Employee
    DigitalOcean Employee badge
    August 13, 2014

    @moxley.stratton: Thanks! I’ve updated the tutorial.

    In the Install Git from the Source section, the linked google code page seems to be abandoned. It only offers versions up to 1.9.0, but the current release is at least 2.1.0-rc2. The Github mirror might be a better bet for downloading source archives.

    @rhombusone: I think the error occurs if you just install git-core only using the apt-get command. And I think you need to move to the next step Install Git from the Source. As you can see at ~/.gitconfig:

    git config --global user.name "NewUser"
    git config --global user.email newuser@example.com

    It say --global user.name and --global user.email.

    Kamal Nasser
    DigitalOcean Employee
    DigitalOcean Employee badge
    January 30, 2014

    @rhombusone: What do you have in <code>/root/.gitconfig</code>?

    Hi there,

    I’m getting “fatal: bad config file line 1 in /root/.gitconfig” after running “git config --list”. I’ve added the information for the username and email. Cant’ work this one out?

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Join the Tech Talk
    Success! Thank you! Please check your email for further details.

    Please complete your information!

    Featured on Community

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more
    DigitalOcean Cloud Control Panel