1

Basically, I want to push all my local changes to a backup bare repository on a remote server and then have the bare repositiory push the changes to production (non-bare) on the same server. Right now, I'm thinking of doing a hook. I'm not using gitosis if that matters. How can I achieve this goal?

I don't know if this is the RIGHT way, but I basically just want to push my local changes to a backup repo (bare) and a non-bare repo.

2 Answers 2

1

TL;DR

You can't successfully push to a non-bare repository.

Three Practical Options

Option 1

Actually, you can push a non-bare repository if you try hard enough, but it won't update your working tree for you even if you do. For example, the push error message says:

You can set 'receive.denyCurrentBranch' configuration variable to 'ignore' or 'warn' in the remote repository to allow pushing into its current branch; however, this is not recommended unless you arranged to update its work tree to match what you pushed in some other way.

You'd have to change the configuration on the non-bare remote, and add a post-receive hook to update the working tree. So, it's generally not useful to do it when there are easier ways to go about it.

Option 2

You could also create a post-receive hook on your bare repository that would use ssh (or similar) to connect to the remote host with the non-bare repository and do a pull whenever the bare repository is updated. This is pretty similar to the previous option, but doesn't require any configuration changes on the non-bare repository.

Option 3

Polling is another option. You could do something similar to https://stackoverflow.com/a/11254771/1301972, where you're polling your bare repository for a pull at timed intervals. This option requires no git configuration or custom hooks at all, so that's what I'd recommend as a general solution if you have access to a crontab.

0

Not sure if this works but.. it may be possible to do a checkout to an --work-tree=<path> (GIT_WORK_TREE environment variable) while still on the bare repo. I didn't find anything either way in the manual pages.

Not the answer you're looking for? Browse other questions tagged or ask your own question.