How to keep a clone of GIT updated?

3

I have created a GIT clone on my backup NAS:

git clone --bare //NAS/GIT/TexRepo //backupnas/backup/GIT/TexRepo.git

Now, continuing to work on the regular repository, what is the best way, practice to have, in order to keep my clone updated?

Do I need to run this command daily? I read somewhere I can edit the push command, is that the solution?

Saariko

Posted 2011-09-15T09:06:49.640

Reputation: 727

Answers

0

You can push from the original repository to the cloned repository. To do so you must first configure a "remote" in the original repository:

cd //NAS/GIT/TexRepo
git remote add backup //backupnas/backup/GIT/TexRepo.git

Now you can push from the original to backup:

git push backup

To keep the clone updated you will have to push regularly.

I do not recommend this but it is possible to automate a push after every commit. Here is an example how to do that.

I consider a push after every commit as going against the designed workflow of git, which specifically allows to rewrite your local history (which hasn't been pushed yet). Read this to learn more about this feature of git.

Think of push as one big commit. You work all day doing local commits and the occasional rewriting of local history. Then, at the end of the day you do one big commit, a push.

lesmana

Posted 2011-09-15T09:06:49.640

Reputation: 14 930

Thanks, is it possible to make that automated? I mean, on any commit, that the change will be also pushed? – Saariko – 2011-09-15T12:08:16.647

You can't pull into a bare Git repository, you have to push commits into the bare repo. – Stacey Richards – 2011-09-15T13:12:28.333

@StaceyRichards: I messed up. I meant fetch. I fixed my answer. – lesmana – 2011-09-15T14:58:16.140

0

Take a look at http://book.git-scm.com/5_git_hooks.html and scroll down to the post-receive or post-update section.

I think what you want is to add a hook in your //NAS/GIT/TexRepo repostory that pushes to your //backupnas/backup/GIT/TexRepo.git repo.

Stacey Richards

Posted 2011-09-15T09:06:49.640

Reputation: 1 292