Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have Ubuntu on my PC.

I want to make all code inside /var/www/ git-versioned.

Where is the best to put my git files and how do I setup git for files inside /var/www/?


Better explanation for my question:

  1. I need to setup git server on my computer that will be only accessible to all PC on local network and for the rest. (the location for my opinion of git server should be /srv/git/)

  2. The files on my computer that i want them to be with git support under /var/www/


share|improve this question
repo inside web-root is extremely bad idea from the POV of security – Lazy Badger Feb 16 '12 at 22:06
why its bad security? – Yosef Feb 16 '12 at 22:13
possibility to open data in repo in case of site-hacks or server-misconfiguration – Lazy Badger Feb 16 '12 at 22:21
the repo should be under /srv/git/ and the code download from git to /var/www/ this what i mean – Yosef Feb 17 '12 at 9:52
up vote 5 down vote accepted

Installing the git client

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.

cd /var/www/some-project
git init
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.

Managing git repositories

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 /srv/gitosis.

If you want more control, grab Gitosis from GitHub instead and change the --home option for the home directory.

sudo adduser \
    --system \
    --shell /bin/sh \
    --gecos 'git version control' \
    --group \
    --disabled-password \
    --home /srv/git \

Then follow the steps in the manual (beware, the Ubuntu version has the user gitosis, whereas the one from GitHub uses git).

You'll find yet another tutorial here, so this stuff is fairly well documented.

share|improve this answer
NITPICK: On all recent releases git-core is a transitional package, that depends on git. The package has no files. – Zoredache Feb 16 '12 at 21:36
see my edit please – Yosef Feb 16 '12 at 22:08
@Yosef Updated answer, but as Zoredache said, this depends on your configuration needs and it's almost impossible to give an answer. You will have to work on this yourself too. – slhck Feb 16 '12 at 22:23

An extremely short startup would be to do something like this.

sudo apt-get install git
cd /var/www
git init
git add .
git commit

You would then have a repository of all the files under /var/www.

You probably should take the time to read the docs though.

share|improve this answer
thanks!but where will be located git version files? – Yosef Feb 16 '12 at 21:53
Git is a distributed version control system. It will keep the files in ~/.git/ unless you clone, setup remotes or perform some other action to push or pull your changes to a different location. – Zoredache Feb 16 '12 at 21:56
P.S. If you can afford a few dollers for a set of videos, I recommend There chapter on cloning is available as a free-demo, so you might want to watch that. – Zoredache Feb 16 '12 at 21:59
see my edit please – Yosef Feb 16 '12 at 22:08
Please see the documentation that @slhck, and I linked to. If you intend to run a server there are a large number of options that you should consider. IMO opinion it is unreasonable to expect us to give you an answer that describes how to setup, and manage a server given the extreme lack of detail you have provided. – Zoredache Feb 16 '12 at 22:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .