2

Some live websites of ours receives automatic code updates. I want these automatically committed (don't worry about the sanity of this, everything is unit tested and only small sites get auto updating).

When I put the repo on the live webserver, the size gets very big.

What is the best way to keep a minimal history of only 1 branch in the local history?

Thank you.

  • Do you have any numbers? If you have only one branch on the repository and then run an aggressive gc to prune all the dangling objects, it should compress the repository quite a bit. – Noufal Ibrahim May 11 '15 at 08:24
  • We usually use 3 main branches remote: dev, staging, master + a whole lot of feature branches. – Maarten De Block May 11 '15 at 08:28
  • Git 2.5 (Q2 2015) supports a single fetch commit! I have edited my answer below, now referencing "[Pull a specific commit from a remote git repository](http://stackoverflow.com/a/30701724/6309)". – VonC Jun 08 '15 at 05:37

3 Answers3

5

You can try making sure the bare repo on the server is created a clone which:

That would be:

git clone -b mybranch --depth 1 /url/of/my/repo

(--depth implies --single-branch)

That should lead to a fairly compact git repo on the server.

Git 2.5 (Q2 2015) even supports a single fetch commit! See "Pull a specific commit from a remote git repository".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Good advices for the best way to keep .git as small as possible is to:

  1. Identify what really makes your git repo big. Is it too much commits? Are the reason binary files? Do you rewrite a huge file all the time?

  2. Do not commit binary files or any bigger texts (an base64 encoded image is almost the same evel as commiting a standard image)

  3. Improve your .gitignore and commit only what is necessary to.

  4. Run minification/scripts outside of your git repository on server (eg. if you use gulp/grunt - then do not commit the result of theirs build process, commit only a source of the process)

  5. If you have lots of small fixes or commits, you can use rebase and once in a while rebase your branch and remove all commits with particular tag (you can tag small commits and after them later on with rebase to keep only a result)

  6. Use multiple git repositories and submodules. You can just clone/remove once in a while one of them that handle yours automatic commits

  7. Use git archive for creating an archive of files from a named tree

Samuel O
  • 2,258
  • 1
  • 16
  • 26
0

Another workflow is : use git archive on your integration server to build an archive (tar.gz or tar.bz2) of the commit you want to deploy, and send this archive to your live servers (scp, sftp, rsync ...).

No more git access from your production servers, no more .git directory either.

LeGEC
  • 46,477
  • 5
  • 57
  • 104