GIT post-receive checkout without root folder
I'm new to git, trying to figure out how to have a website updated with each push by doing a checkout to the web root. I have searched stackoverflow and only found topics about how to clone, which is not what i want. So far i have set up my local and remote repos, and a post-receive hook:
#!/bin/sh
GIT_WORK_TREE=/path/to/website/httpdocs git checkout -f
My problem is that the project root folder is included in the checkout... when i push contents to the remote repo, i end up with something like
/path/to/website/httpdocs/project_root/index.php
What i would like to achieve is having
/path/to/website/httpdocs/index.php
How can I omit the project root folder while checking out?
Solution 1:
If:
- /path/to/website/httpdocs is a git repo
- /path/to/project_root is a git repo (i.e. there is a
.git
directory)
Then you can use in your post-receive
hook:
git --git-dir=/path/to/project_root/.git --work-tree=/path/to/website/httpdocs checkout -f
But if you are pushing to project_root
, it is rather a bare repo, in which case, its root directory should be called /project_root.git
, and the post-receive
hook would look like:
git --git-dir=/path/to/project_root.git --work-tree=/path/to/website/httpdocs checkout -f
In any case, project_root
must be the root of a git repo.
The OP choppingblock comments:
it seems that the problem is caused by the eclipse git plugin (EGit), which automatically creates a root folder with the name of the project.
I now worked around it by changing the path to thewebroot
from/path/to/website/httpdocs
to/path/to/website/httpdocs/project_root
.