2

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?

choppingblock
  • 110
  • 1
  • 1
  • 9
  • 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 the webroot from `/path/to/website/httpdocs`to `/path/to/website/httpdocs/project_root` – choppingblock Apr 12 '13 at 12:30

1 Answers1

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 the webroot from /path/to/website/httpdocs to /path/to/website/httpdocs/project_root.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • the repo is in `path/to/website/git/myrepo.git` i'm pushing to this from my local repo, but want to checkout to `path/to/website/httpdocs` (which is not a repo) – choppingblock Apr 10 '13 at 16:50
  • @choppingblock then the second post-receive hook I mention will do just that. – VonC Apr 11 '13 at 05:58
  • turns out the problem was elsewhere (see comment on the question). since your answer was correct anyway, i set it to accepted. – choppingblock Apr 12 '13 at 12:31
  • @choppingblock ok. I have added your comment to the answer for more visibility. – VonC Apr 12 '13 at 12:45