This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
The lines that the user needs to enter or customize will be in red in this tutorial! The rest should mostly be copy-and-pastable.
Git is a distributed version control system released to the public in 2005. The program allows for non-linear development of projects, and can handle large amounts of data effectively by storing it on the local server. This tutorial will cover two ways to install Git.
Installing Git with apt-get is a quick and easy process. The program installs on the virtual private server with one command:
sudo apt-get install git-core
After it finishes downloading, you will have Git installed and ready to use.
If you are eager to download the most recent version of Git, it is generally a good idea to install it from the source.
Quickly run apt-get update to make sure that you download the most recent packages to your VPS.
sudo apt-get update
Prior to installing Git itself, download all of the required dependancies:
sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
Once they are installed, you can download the latest version of Git from the google code page.
wget https://git-core.googlecode.com/files/git-1.8.1.2.tar.gz
After it downloads, untar the file and switch into that directory:
tar -zxf git-1.8.1.2.tar.gz
cd git-1.8.1.2
If you want to do a global install, install it once as yourself and once as root, using the sudo prefix:
make prefix=/usr/local all sudo make prefix=/usr/local install
If you need to update Git in the future, you can use Git itself to do it.
git clone git://git.kernel.org/pub/scm/git/git.git
After Git is installed, whether from apt-get or from the source, you need to copy your username and email in the gitconfig file. You can access this file at ~/.gitconfig.
Opening it following a fresh Git install would reveal a completely blank page:
sudo nano ~/.gitconfig
You can use the follow commands to add in the required information.
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
If you avoid putting in your username and email, git will later attempt to fill it in for you, and you may end up with a message like this:
[master 0d9d21d] initial project version Committer: rootYour name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly: git config --global user.name "Your Name" git config --global user.email you@example.com After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author
This tutorial covered how to install Git on your virtual private server. Stay tuned for a second tutorial on Git Basics.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
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!
i just realized how resourceful you guys are!!! :)
Thank you! Please let me know if there are any other topics you would like to see covered. =]
awesome tutorial. I’m waiting it basic… :)
Hi! this only works if you are running certain versions and set ups. The command
root@nova-controller:~# apt-get install git -y Reading package lists… Done Building dependency tree Reading state information… Done Package git is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source
E: Package ‘git’ has no installation candidate
That would depend on what repos you are contacting to install packages but it should be supported, have you made any repo changes for apt?
git config --list does not work,it shows an error fatal: bad config file line 2 in /root/.gitconfig what to do now…?
In a user’s home directory the .gitconfig file is the user’s specific config variables.
You should review that file and see if you have any errors in it as whenever you run git as root that file will be referenced.
Also depending on how your application is setup you may want to consider running all of your git repos under another user who is not root for security. In that case the /root/.gitconfig would not be referenced.
How about a post commit hook, so when after I push a commit code to git repo, it will auto upload php files to the lamp/web server which is also hosted by digital ocean. Hope you will have a tutorial for this. I am a newbie.
You can set something up like that, but it kind of breaks the convention behind git, which is meant to commit changes to the repo and then delpoy the code separately.
You can use something like capistrano to automate the deployment of your git code after you have updated. This way you can do multiple commits and work with other collaborators without having to worry that each most recent commit automatically gets deployed as this can be error prone, by deploying code that hasn’t yet been thoroughly tested.
Super and Easy steps given here!!!