I have a remote git repository with big history and slow connection channel. Where are some local users, and slow push/pull after big commits or cloning from scratch for new users are big problems, now. I want to create local mirror of it. Local changes must be committed to local repo, and sync with remote in background. I understand that this problem is in demand, but I have not found any solution yet (I am not admin of remote repo, I just try to simplify local work with it).
Asked
Active
Viewed 7,219 times
7
-
This previous post shall help you achieve a mirror of a remote repo http://stackoverflow.com/questions/3959924/whats-the-difference-between-git-clone-mirror-and-git-clone-bare – Ozair Kafray Jul 16 '12 at 10:35
-
1Are only your local users committing to the slow remote repo or are there other people somewhere else doing work? – Benjamin Bannier Jul 16 '12 at 10:35
-
@honk Yes. Local users doing 99% of work, remote users needs read-only access (or with very rare commits). I think, that speed of remote-local background sync will be appropriate for remote users i think they must have delay if sync is not ended yet. – exbluesbreaker Jul 16 '12 at 10:50
2 Answers
3
Since you write in the comments that the people behind the slow connection would be doing most of the work, I would suggest you setup the slow remote site to be a mirror of your local repo you would commit against.
First make a bare clone of slow remote on a local server
$ git clone --bare git://slow/repo.git
You local people should now only commit to that clone, not the slow remote.
Then set up a cron job or something similar to push changes in your local repo to the slow site with
$ git push origin --mirror
By using --mirror
you tell git to push all branches and tags.

Benjamin Bannier
- 55,163
- 11
- 60
- 80
-
Thanks! I test it for my test github repo and it works. Full clone of real remote repo take 20 hours or more, and i apply this solution for it in the near future. – exbluesbreaker Jul 16 '12 at 12:00
-
1I found, that this solution will drop all changes, made on remote repo without access through local mirror. Is there any way to merge changes? Commits to remote repo is rare thing, but i don't want to lose such commits. E.g. first time some local developers may continue commits to remote repo directly by mistake. – exbluesbreaker Jul 20 '12 at 04:30
-
@exbluesbreaker: You could drop the `--mirror`, but then you would need to specify which branch you want to push, e.g. `git push origin master`. Then you'd probably also want to add `--tags` to the push to push tags as well. `--mirror` will push all local branches and tags, so it does all this automatically (but will overwrite remote changes). – Benjamin Bannier Jul 20 '12 at 07:38
-
What would the command be to push everything (all branches, all tags, etc) without overwriting remote changes? – Thorbjørn Ravn Andersen Dec 17 '12 at 07:10
-
1@ThorbjørnRavnAndersen If I'm not wrong, `git push origin "refs/*:refs/*"`. Notice that `"refs/*:refs/*"` will reject non-fast-forward updates, whereas `"+refs/*:refs/*"` will force the updates (overwrite) – Alberto Jan 25 '13 at 08:49
1
You should be able to make shallow clones with
git clone --depth=20 url-to-your-repo some-path
This should allow you to not bother with most of the history.

Adam Dymitruk
- 124,556
- 26
- 146
- 141