This question already has an answer here:

I'm adopting a git push to deploy method where I setup a bare repository on the live server which I push my local changes to. Using a post-update hook, executed after I've pushed I pull my changes to the directory housing the live site.

This method works extremely well but as we are using virtual servers sometimes disk space can be an issue, especially for out larger sites. My concern is that the bare repository and the repository where the site actually resides and is accessible means two (possibly large) repositories on the server, no?

Is i possibly to lighten this up a little? In my post-update hook, is it possible to only pull the latest changes and overwrite the previous files. Or, should I use 'cp' instead of 'git pull' for this? I suppose after every commit I could just remove all files in the site's directory and then do a pull, then delete the .git directory?

Anyway would appreciate hearing from anyone how this is best handled. Thank you

marked as duplicate by user40980, jwenting, Dan Pichelman, GlenH7, gnat Nov 12 '14 at 21:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


"git clone" has a couple of options that might help:

  • "git clone --local" tries to save space by hardlinking files if you are cloning a repository on the same machine
  • "git clone --shared" points your cloned repository over the where you cloned it from (on the same machine) and avoids copying objects over. There is a serious warning around this, read "man git-clone"
  • "git clone --reference" is similar to "--shared"

git tries to use "clone --local" by default if you are cloning a repo located on the same machine, so you might already be benefiting from that.


Here are two other options.

Instead of pushing to an intermediate repository, have the repository you push to be the directory for the live site. In there, you can simply create a post-update hook that calls git checkout HEAD. This way, the repository is stored only once.

A second option, if you cannot change where you push to, is to use git archive. That command exports the contents of a commit as a tar or ZIP file. If you read through git help archive, it has the following example, which may be relevant to your use case:

git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)

Create a tar archive that contains the contents of the latest commit on the current branch, and extract it in the /var/tmp/junk directory.

You could wire up something similar to export the HEAD commit into your live site directory.

Not the answer you're looking for? Browse other questions tagged or ask your own question.