3

I have a website that is running on a Windows 2008 server. I want to know what is the best way to manage that site using git. Ideally I want an automated deployment, using a post-receive hook or similar.

I do have a Linux server that I typically use as my git origin server, so I can utilize that if it makes things easier. Typically my post-receive file there looks like this:

#!/bin/sh
GIT_WORK_TREE=/var/www/example.com git checkout -f

Obviously that won't work as-is on Windows without something else in place.

My Windows server supports FTP but I'd like to use something more secure if possible.

Peter Meth
  • 405
  • 5
  • 12

2 Answers2

0

You can use a Windows path in your bash script (which will be interpreted by msysgit on windows).

/C/my/path/...

You can see here an example of a fairly complex post-checkout hook (not a post-receive, but it can illustrates what you can do on Windows in a bash hook script).

More details in "Combining mingw and git".

Actually, Adam Rofer mentions in the comments:

If you use normal windows sharing, you can access git repositories via this path syntax:

//computername/folder/repo.git 

assuming folder is the shared folder accessible to your login via normal windows folder sharing. Msysgit seems to play well with this.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ok, well that might take care of the post-receive hook, but how do I push to the Windows server from a remote PC. Normally I use ssh, but I don't know how that works on Windows or if it is even practical to do. – Peter Meth Feb 09 '12 at 14:19
  • @Peter: I usually put an Apache server in front of my repo and use an https session + the `git-http-backend` script (http://stackoverflow.com/questions/5264949/cannot-push-git-to-remote-repository-with-http-https/5265022#5265022) – VonC Feb 09 '12 at 14:30
  • That sounds like an interesting alternative that I will have to check out at some point. I'd prefer to go the ssh route for now so it can be similar to my existing linux setup. – Peter Meth Feb 09 '12 at 18:34
  • If you use normal windows sharing, you can access git repositories via this path syntax: `//computername/folder/repo.git` assuming `folder` is the shared folder accessible to your login via normal windows folder sharing. Msysgit seems to play well with this. – Adam Rofer Feb 09 '12 at 18:48
  • @AdamRofer Interesting. I have included your comment in the answer for more visibility. – VonC Feb 13 '12 at 15:53
0

I ended up using these instructions to setup Cygwin + OpenSSH + Git which got me most of the way there.

http://www.shannoncornish.com/blog/2009/04/git-server-windows-2008/

In the post-receive I had to remove the first line #!/bin/sh due to some permission issues, and I added a symlink to my webroot from within Cygwin like so:

ln -s /cygdrive/c/inetpub/wwwroot /var/www

So the post-receive file ended up looking very similar to before but without the first line

GIT_WORK_TREE=/var/www/example.com git checkout -f
Peter Meth
  • 405
  • 5
  • 12
  • Interesting but I would *really* avoid using Git within Cygwin (it is incredibly *slower* than a msysgit distro. I would rather use `sshd` from Cygwin with msysgit: http://superuser.com/questions/325639/make-msysgit-work-with-cygwin-ssh – VonC Feb 09 '12 at 18:58
  • yes i have noticed it is really slow, though for most of the stuff I do that is not a big deal. also i am having trouble getting my post-receive hooks to work. – Peter Meth Feb 09 '12 at 19:17
  • @VonC as per your suggestion I switched to msysgit using cygwin sshd. It was much more difficult to setup. I think I finally got it going, but now I have issues pulling and pushing. When I tried `git clone ssh://git@myserver.com/var/git/example.git` it said it was not a git repository. On a whim I tried `git clone ssh://git@myserver.com:c:/cygwin/var/git/example.git` it worked. However, when I try to push from the clone it says that `/cygwin/var/git/example.git` is not a valid git command. It seems the paths are messed up somehow. – Peter Meth Feb 10 '12 at 04:20
  • Interesting. That could warrant another question which would explain *in details* your new setup (with version number of all products involved, including your version of Windows), and would mention (again *in detail* your error messages. And link to this question for the original context. – VonC Feb 10 '12 at 06:41
  • http://stackoverflow.com/questions/9263410/git-push-pull-paths-not-working-to-windows-origin-running-msysgit-cygwin-sshd – Peter Meth Feb 13 '12 at 15:47