Reputation: 3534
I'm starting to deploy a few website plugins via git.
I've been through a number of tutorials on the web and all of them recommend creating a bare remote repository on the web server with a post-update hook to checkout into the DocumentRoot directory. I've gotten this all working without too many issues.
Why are we separating the respository from the working directory? What's wrong with just using the DocumentRoot directory as the repository and then using htaccess to prevent public access to any .git content?
Upvotes: 9
Views: 2906
Reputation: 691
Use DocumentRoot as git working directory:
Use separate bare git repostory
So, seems separate bare git repo is more clean and easy to use, except need to setup a post-update hook.
Plan 1 is also work able, use it in a small project or develope mechine is fine, but beware the access privilege to .git directory, especially when changing web server. eg: nginx doesn't support .htaccess, which is often stored in git with other project files together.
Upvotes: 0
Reputation: 113876
There are several questions here that, while related are actually separate:
1 - Why are we separating the respository from the working directory?
Because git prevents you from pushing to a checked out branch by default. You can therefore never push to a working directory because by definition, if it's on disk it's checked out.
2 - All of them recommend creating a bare remote repository on the web server
Implied question is: why a bare repo?
Well, a bare repo is simply a git repo with nothing checked out. Therefore you can push to any branch on a bare repo. Some people consider this simpler to maintain.
Second implied question: is there an alternative to bare repos?
Yes, as mentioned the restriction is only on checked out branches. So you can still freely push to a non checked out branch - maybe "deploy" and then have a hook to merge that non checked out branch to your working directory.
Upvotes: 0
Reputation: 363567
Actually the security risks inherent in a poorly configured htaccess are a good reason by themselves, but the main reason is that by default, you can't push to the checked-out branch of a non-bare repo. (It can be enabled, but then requires a git reset --hard
to update the work tree, and is no simpler than having a separate deployment directory.)
Upvotes: 5