问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/24948490/how-do-i-connect-a-copy-an-archive-not-a-clone-of-a-git-repository-to-its-rem