dr11
dr11

Reputation: 5746

Auto deploy git changes

On my server I have repository at /var/repo/site.com.git/ and also public site folder at /var/www/site.com/

Working locally I'd like to push changes to the server and automatically deploy all changes to a public folder.

In a /var/repo/site.com.git/hooks/ I created executable file post-receive with such content:

#!/bin/bash
GIT_WORK_TREE=/var/www/site.com git checkout -f

Now once any change was pushed to a repository my public folder becomes updated.

But the problem is that this update becomes marked as modified in a public folder. And from my prospective it's expected that after such update public folder becomes up-to-date without any modifications.

Also I tried to call hard reset with pull commands without any success.

Upvotes: 2

Views: 188

Answers (1)

dr11
dr11

Reputation: 5746

In case it is acceptable to force reset on public before update post-receive script could be like:

#!/bin/bash
git --work-tree=/var/www/site.com --git-dir=/var/www/site.com/.git checkout -f
git --work-tree=/var/www/site.com --git-dir=/var/www/site.com/.git pull

In case you'd like only to pull updates you can use such script:

#!/bin/bash
git --work-tree=/var/www/site.com --git-dir=/var/www/site.com/.git pull

Upvotes: 1

Related Questions