Is it possible to have a Git repository without history? For example, I have a local Git repository where I work and I want to push the latest version to the production server. No history should be stored on the production server. How can I do that?
-
1`git clone --depth 1` – zero323 Dec 20 '14 at 13:45
-
4So, you don’t really want to push your git repo, you just want the current sources? Check out if rsync is your tool. – Christopher Creutzig Dec 20 '14 at 13:57
-
@ChristopherCreutzig, can I see what files has been changed and diff and by whom they have been changed before I commit with rsync? – ilhan Dec 22 '14 at 10:18
-
@ilhan No, to do that, you need history. But you were asking about not having any hostory. You can check which files were changed, though, `rsync -n`. – Christopher Creutzig Dec 23 '14 at 22:18
3 Answers
You can see if the command git archive
fits the bill:
Creates an archive of the specified format containing the tree structure for the named tree, and writes it out to the standard output.
If<prefix>
is specified it is prepended to the filenames in the archive.
git archive
behaves differently when given a tree ID versus when given a commit ID or tag ID.
- In the first case the current time is used as the modification time of each file in the archive.
- In the latter case the commit time as recorded in the referenced commit object is used instead.
Once you have created an archive, you can copy it and unzip it on the server side: no git required on the server.
Since you have to copy only one file (instead of a large number of files with rsync over your working tree), the transfer is easier.

- 1,262,500
- 529
- 4,410
- 5,250
What you want is a post-receive
or post-commit
hook:
If you're purely working local and never push anything anywhere, use the
post-commit
hook. It gets triggered after each commit and gives you the opportunity to do whatever you want, including pushing your lastest changed files to somewhere using whatever tool you want to (includinggit archive
as VonC recommends)If you're pushing 'release' versions of your work to a remote server (or another local blessed repo, doesn't matter for this case), use the
post-receive
hook. It gets invoked on a server repo when a new version was pushed. From here, the process is pretty much the same as for thepost-commit
hook.
For a deeper discussion on the hooks, have a look at the Git Book and the reference:
You can use --depth
to create a shallow clone with a history truncated to the specified number of commits.
To only retrieve the last commit use --depth 1
.
git clone git@github.com:account/repository.git --depth 1
If you need the recent 5 commits, you’ll specify --depth 5
Implies --single-branch
unless --no-single-branch
is given to fetch the histories near the tips of all branches. If you want to clone submodules shallowly, also pass --shallow-submodules
.
From: https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---depthltdepthgt

- 4,190
- 2
- 30
- 39