Git push error '[remote rejected] master -> master (branch is currently checked out)'

前端 未结 30 2265
半阙折子戏
半阙折子戏 2020-11-22 00:07

Yesterday, I posted a question on how to clone a Git repository from one of my machines to another, How can I \'git clone\' from another machine?.

I am now

30条回答
  •  时光说笑
    2020-11-22 00:22

    With a few setup steps you can easily deploy changes to your website using a one-liner like

    git push production
    

    Which is nice and simple, and you don't have to log into the remote server and do a pull or anything. Note that this will work best if you don't use your production checkout as a working branch! (The OP was working within a slightly different context, and I think @Robert Gould's solution addressed it well. This solution is more appropriate for deployment to a remote server.)

    First you need to set up a bare repository somewhere on your server, outside of your webroot.

    mkdir mywebsite.git
    cd mywebsite.git
    git init --bare
    

    Then create file hooks/post-receive:

    #!/bin/sh
    GIT_WORK_TREE=/path/to/webroot/of/mywebsite git checkout -f
    

    And make the file executable:

    chmod +x hooks/post-receive
    

    On your local machine,

    git remote add production git@myserver.com:mywebsite.git
    git push production +master:refs/heads/master
    

    All set! Now in the future you can use git push production to deploy your changes!

    Credit for this solution goes to http://sebduggan.com/blog/deploy-your-website-changes-using-git/. Look there for a more detailed explanation of what's going on.

提交回复
热议问题