简体   繁体   中英

Automatically `pull` when there is what to pull to my repo: `post-merge` git server hook using PHP

What I want to accomplish:

I have juts installed git on my development server. I create a branch out of my 'develop' branch, work on my new feature branch, commit, and when I'm done - I merge the new feature branch with the 'develop' branch.

To apply the changes for the 'develop' branch on my development server I have to log in to my server and use git pull - which I'm trying to prevent and happen automatically - when there is something to pull from my development server - it will be done automatically.

I hope I'm clear about that I'm trying to accomplish ;)

What I have done up till now is:

  1. Created a folder inside my project /www/hooks/ and added a file called post-merge : Following git documentation - this should get triggered whenever I merge a branch.

  2. Inside this folder I added the text:

    在此处输入图片说明

which should execute whatever is in between the backticks symbol ( ` ) as a shell command (following this PHP documentation)

  1. Inside the folder /www/.git/hooks/ I added a symbolic-link to the file I previously mentioned with the same exact name: /www/hooks/post-merge :
 sudo ln -s -f /www/hooks/post-merge /www/.git/hooks/post-merge 
  1. I gave the linked file under /www/.git/hooks/post-merge 775 file permission as the other files.

Some notes:

  • My repo is on Bitbucket

  • My directory /www/homepage/ is the one with the index file, so nothing can run outside of it on a browser (apache2 points to it..) - (but i guess there shouldn't be a problem since it's self executed via /.git/hooks ?)

  • I tried renaming both my files (the one under /www/.git/hooks/ & /www/hooks/ ) to post-merge.php and this didn't work.

just to have Carriage return

#!/bin/bash 
git --git-dir "path/master/.git" --work-tree "path/master" pull origin master 

you could try this in your post-merge

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM