Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I connect a COPY (an archive, not a clone) of a git repository to its remote?

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 [email protected]/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

like image 658
tjg Avatar asked Dec 30 '25 08:12

tjg


1 Answers

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.

like image 62
VonC Avatar answered Jan 01 '26 23:01

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!