0

I might probably just have a lack of basic git knowledge, but I need some help here to make that clear.

I have a local git repo. I also have a webserver on which I want to deploy my code.

My thoughts are to init a git repo on the webserver (probably a bare one since I don't want to make any changes there directly) and then add that repository as a remote to my local one.

So I executed git init --bare my-repo.git on my webserver, added the remote with git remote add develop ssh://user@webserver/path/to/git-repo/my-repo.git.

So far so good, I can now successfully push my changes to my webserver with git push develop develop. I can also see the pushed commits there with git log develop.

The problem now is that I can't see my project files there. Of course I can't, because there is no work-tree since it is just a bare repo. But how in heaven can I make the project (which is a web page containing an index.php, etc.) visible?

Edit: My problem was not (as suggested by a "possible dublicate"-request) my missing knowledge about the difference of a bare and a regular repo. My problem was the correct usage of a checkout with manually set work-tree and git-dir as well as the needed folder structure for it. Thanks to @muecas's comment I got it.

Froxx
  • 957
  • 4
  • 14
  • 27
  • The answer would appear to be: make it a non-bare repo. – Oliver Charlesworth May 14 '18 at 22:32
  • I tried that, but even then the files are not transmitted on push. And since I just want to make changes to this repo by pushes it's recommended to make it bare. – Froxx May 14 '18 at 22:34
  • You are going well. The problem is that you need your bare repo outside your document root, and then thru a post-receive hook, checkout the files to the document root (defining the document root as the working directory). The bare repo does not have a working directory so it won’t have any checked out files in its root. – muecas May 14 '18 at 23:11
  • Possible duplicate of [What is the difference between "git init" and "git init --bare"?](https://stackoverflow.com/questions/7861184/what-is-the-difference-between-git-init-and-git-init-bare) – phd May 14 '18 at 23:57
  • https://stackoverflow.com/questions/279169/deploy-a-project-using-git-push – phd May 15 '18 at 00:00
  • @muecas Oh, I see! I got it working by creating the git repo out of my project root dir and executed `git --work-tree="home/user/my-project" --git-dir="home/user/git/my-repo.git" checkout my-branch -f`. I just have another issue with the hook now. It does not trigger. I'm using this code: https://gist.github.com/noelboss/3fe13927025b89757f8fb12e9066f2fa#file-post-receive – Froxx May 15 '18 at 00:10
  • @muecas Doesn't matter, `chmod +x` did the job... Thanks a lot for your help! – Froxx May 15 '18 at 00:14
  • Great! Glad i could help. – muecas May 15 '18 at 00:40

0 Answers0