Setting up post-receive hook for bare repo

后端 未结 3 1446
被撕碎了的回忆
被撕碎了的回忆 2020-12-09 19:09

I have a bare repo set up in my ubuntu server.

After I push to my bare git repo to the server:

$ git push origin master

I want the

相关标签:
3条回答
  • 2020-12-09 19:15

    I'd go with something like

    #!/bin/sh
    
    cd /central/workfiles
    git pull
    exit
    

    Save the above script as post-receive and place it in the hooks/ directory of your bare repo.

    Bottom line don't forget to make it executable

    chmod +x post-receive
    
    0 讨论(0)
  • 2020-12-09 19:17

    i use the post receive hook like this

    #.git/hooks/post-receive
    
    #!/bin/sh
    GIT_WORK_TREE=/srv/http/sitedir/ git checkout -f
    

    yes, make sure to make it executable.

    0 讨论(0)
  • 2020-12-09 19:24

    I prefer specifying the working tree and git directory instead of relying on a cd:

    /bare/repo.git/hooks/post-receive
    
    #!/bin/sh
    GIT_WORK_TREE=/central/workfiles GIT_DIR=/central/workfiles/.git git pull origin master
    exit
    

    As commented below by ChrisV, you can also rely one a git checkout instead of a git pull

    I believe git checkout -f is safer than git pull, as the merge which is part of the pull has the potential to make things messy if manual fixups should be needed.

    But that means /central/workfiles is not a "non-bare" git repo. It is just a folder where you checkout the content of the bare repo /bare/repo.git.
    See Brian Thomas's answer for an example of that approach.

    That would not fit the OP specification.

    0 讨论(0)
提交回复
热议问题