3

I'd like to know to connect and sync a COPY (an archive, not a clone) of a git repo with its remote repo.

Background: I have a local and remote repository. I zip up my local repository using git archive and then copy it to a server:

$ git archive --format=tar HEAD | gzip > myarchive.tar.gz

Question: After unzipping the archive on the server, how do I connect and sync the server's copy with the remote repository again?

If I do this:

$ git init
$ git remote add origin git@github.com/myusername:reponame.git
$ git fetch origin

git status still reports everything as being untracked.

What should I be doing so that my unzipped folder is perfectly in sync with the remote repo, and so I can simply pull any future commits to the remote repo?

Many thanks, Tim

tjg
  • 105
  • 1
  • 7

1 Answers1

2

Don't do an archive: do a git bundle: that will give you one file, except you will be able to pull from it once copied in the remote location.

See more at "How can I email someone a git repository?"

That bundle can be incremental too (see also "Difference between git bundle and .patch").
Meaning you don't have to copy over the full repos, only the missing commits since the last backup.

I have a scripts which goes to all my bare repos and make a full backup once a week, incremental backups every day (if new commits are detected): sbin/save_bundles.


As Nevik Rehnel mentions in the comments, git archive would only save one revision, which would make any synchronization in the remote repo incomplete (missing intermediate commits).

Another approach is to tar the all repo, but that includes too much (including possible private sensitive files, or hook scripts). git bundle is the git way.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • it should be mentioned that the reason why `archive` is inappropriate here is that it only packs up the contents of a single revision without any history information -- if it should be re-integrated into a git repo, that information is important, though. – Nevik Rehnel Jul 25 '14 at 06:32
  • @NevikRehnel Indeed. I have included your comment in the answer for more visibility. – VonC Jul 25 '14 at 06:38
  • Super! Thanks so much, @VonC and NevikRehnel. I appreciate the explanation and links. Regards, Tim – tjg Jul 28 '14 at 03:12