Git comes in the Ubuntu packages.
sudo apt-get -y install git
After that, you can easily just create an empty Git repository wherever your code is.
git add some-file
git commit -m "First commit."
Although it can be argued that keeping version controlled files in
/var/www is not a good idea. You should probably only deploy projects there.
If you want a Git server and push your stuff somewhere, you should look at Gitosis. On Ubuntu, that is:
sudo apt-get -y install gitosis
The Ubuntu community manual also has an extensive tutorial on setting up Gitosis, as well as the Arch wiki I linked to above. The default setup will take care of where to put your files, in this case
If you want more control, grab Gitosis from GitHub instead and change the
--home option for the home directory.
sudo adduser \
--shell /bin/sh \
--gecos 'git version control' \
--home /srv/git \
Then follow the steps in the manual (beware, the Ubuntu version has the user
gitosis, whereas the one from GitHub uses
You'll find yet another tutorial here, so this stuff is fairly well documented.