1

I am currently using git post-receive hook to push my code to server.In the future I am planning to deploy another project in this server. So there will be 2 projects locally and each of them will be a separate git repository. How can I transform post-receive so when i push from dir1 it will push code to dir1 directory, and when i push from dir2 it will push code to dir2 directory.

Until now i have a simple line which gets the pushes i make and send them to the folder directory.

trying to learn
  • 129
  • 3
  • 11
  • This question makes no sense to me. The hook is running on a server, which is a machine unrelated to the computer that you (or someone else) is using when you run `git push`. How should the server know anything about *your* directory? That's a bit like me trying to tell what color your phone is, when you call me. On the other hand, if you want to know what the current directory (or, better, the *Git* directory) is on the *server*, just ask Git: `git rev-parse --git-dir` (note that the result may be a *relative* path; use `realpath` on Linux to convert to absolute path). – torek Mar 17 '17 at 22:53
  • @torek What I really want is to manage 2 projects locally and push them separately to server via git , using post-receive. As far as I know i cannot write 2 paths in **post-receive** hook. – trying to learn Mar 18 '17 at 08:40
  • Why do you want to write even *one* path in your post-receive hook? What exactly do you intend to put in your post-receive hook? (What code do you have now, in other words?) – torek Mar 18 '17 at 08:43
  • `#!/bin/bash git --work-tree=/var/www/laravel --git-dir=/var/repo/site.git checkout -f` This is my current code.I am working on another project and I want to deploy it aswell via git on server. – trying to learn Mar 18 '17 at 09:30
  • OK, now we're getting somewhere. The script you are using is not very sophisticated (see http://stackoverflow.com/q/279169/1256452 for other methods) but it has one big advantage: it's just *one line long* (excluding the header line). It's hardly going to hurt much to copy it to a second, different script in a second, different repository, is it? – torek Mar 18 '17 at 10:02
  • @torek Oh, I got it! Thank you a lot! I was misunderstanding that every git repository has it is own hooks.Thanks again. – trying to learn Mar 18 '17 at 10:12

0 Answers0