How to update a git clone --mirror?

GitMirrorGit CloneGit RemoteGit Fetch

Git Problem Overview


I have created a git repository to mirror a live site (which is a non-bare git repository):

git clone --mirror ssh://[email protected]/path/to/repo

Now, to keep this mirror clone updated with all changes from its remote origin, which command or commands I must use?

I'd like to keep everything updated: commits, refs, hooks, branches, etc.

Thanks!

Git Solutions


Solution 1 - Git

This is the command that you need to execute on the mirror:

git remote update

Solution 2 - Git

Regarding commits, refs, branches and "et cetera", Magnus answer just works (git remote update).

But unfortunately there is no way to clone / mirror / update the hooks, as I wanted...

I have found this very interesting thread about cloning/mirroring the hooks:

http://kerneltrap.org/mailarchive/git/2007/8/28/256180/thread

I learned:

  • The hooks are not considered part of the repository contents.

  • There is more data, like the .git/description folder, which does not get cloned, just as the hooks.

  • The default hooks that appear in the hooks dir comes from the TEMPLATE_DIR

  • There is this interesting template feature on git.

So, I may either ignore this "clone the hooks thing", or go for a rsync strategy, given the purposes of my mirror (backup + source for other clones, only).

Well... I will just forget about hooks cloning, and stick to the git remote update way.

  • Sehe has just pointed out that not only "hooks" aren't managed by the clone / update process, but also stashes, rerere, etc... So, for a strict backup, rsync or equivalent would really be the way to go. As this is not really necessary in my case (I can afford not having hooks, stashes, and so on), like I said, I will stick to the remote update.

Thanks! Improved a bit of my own "git-fu"... :-)

Solution 3 - Git

See here: https://stackoverflow.com/questions/5563349/git-doesnt-clone-all-branches-on-subsequent-clones/5563660#5563660

If you really want this by pulling branches instead of push --mirror, you can have a look here:

https://stackoverflow.com/questions/5559321/fetch-all-in-a-git-bare-repository-doesnt-synchronize-local-branches-to-the/5559586#5559586

This answer provides detailed steps on how to achieve that relatively easily:

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJ. BruniView Question on Stackoverflow
Solution 1 - GitralphtheninjaView Answer on Stackoverflow
Solution 2 - GitJ. BruniView Answer on Stackoverflow
Solution 3 - GitseheView Answer on Stackoverflow