I'm burning my stuff on a dvd, before a quick reinstall. Never done that with git, being a recent user. So I'm just checking with you guys. If I understood correctly, I just need to backup my project directory project_name (which has .git inside it) watching for hidden files along with it, and when I copy it onto the "new" machine, and install git again, I resume like nothing happened ? Correct ?
2 Answers
If you only want to backup project files (without history), you can use git archive
(that way, I do not have to "watch for hidden file")
The script git-archive-all.sh
will actually archive all git repositories and submodules in the current path.
Useful for creating a single tarfile of a git super-project that contains other submodules.
As Charles Bailey rightly mentions in the comments, git bundle
is more appropriate, to preserve the history. (git bundle
was introduced in February 2007).
See Backing up a git repository with git bundle
git bundle
was designed to allow transfer of git commits when there is no direct connection between repositories (i.e.: offline) but using patches is not an option because of the large number of commits and multiple branches.
Agit bundle
is just one file which can be very easily created and again imported as it can be treated like another remote. A quick example:
jojo@dualtron:~/devel$ git bundle create ~/devel.bdl master test
and a bundle is saved under
~/devel.bdl
containing my master and test branches.
If I am now at repository B I just usejojo@dualtron:~$ git ls-remote devel.bdl
which shows me the branches stored in the bundle.
To use the bundle I simple treat it like a remote, using git fetch (for example)
jojo@dualtron:~/git/repoB$ git fetch ~/devel.bdl refs/heads/\*:refs/remotes/bundle/\*
-
1For a backup, I think that `git bundle` is more appropriate than `git archive`. `git archive` just creates tarballs of trees (snapshots) but doesn't preserve commits and history. `git bundle` create without any dependencies can be a freeze dried repository of as many branches as you like. – CB Bailey Jan 12 '10 at 07:45
-
1@Charles: thank you for the comment. I have edited my answer accordingly. – VonC Jan 12 '10 at 08:06
-
1Is there any advantage in using "git bundle ..." over just select all/copy/paste the whole lot ? For this specific case (just burning to dvd or placing on usb temporarily) ? – Rook Jan 12 '10 at 16:19
-
@ldigas Theoretically your burning program could screw up git's filenames, unless you put the repo into an archive file. But if you archived anyway, using bundle yields the advantage of being directly usable as a remote (read-only of course, if on CD) – Tobias Kienzler Nov 05 '13 at 10:49
yep. that's right.

- 47,141
- 22
- 87
- 101
-
4
-
4I tried just saying "yep." but it won't let me post answers smaller than 15 characters :P A git repository is simply a folder(and it's sub folders) with a .git directory initialized with git init. you can move this folder anywhere and it will work with git. – Charles Ma Jan 12 '10 at 05:47
-
I'm new to Git too, hence coming upon this question. Even though `git bundle` seems like a better option according to other answers here, if backing up files manually, surely only the _.git_ folder needs to be backed up? Can the current state of any branch be reconstituted properly from just that folder's contents? – Drew Noakes May 25 '10 at 16:37