推送到远程服务器和Github [英] Push to remote server and Github

查看:107
本文介绍了推送到远程服务器和Github的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总结:我想在本地编辑文件,然后推送到Github和我的web服务器。



我有两个远程设置没有问题,所以现在我有点能够做到这一点;但是,我必须在本地检出分支A,并在服务器上分支B.然后我必须SSH进入服务器,并检查分支A(我想要的)。我真的不想要或不需要第二个分支,但很多帖子都建议你不能或不应该推送到非裸仓库。一定会有更好的办法。即使只是使用rsync会比这更容易(我做了一段时间)。

奇怪的是,这在Github上从未发生过。几乎所有我的回购只有一个分支,我从来没有收到这个警告。



警告消息说你可以设置 receive.denyCurrentBranch 忽略,但我不知道它有多安全/理智。我希望有人能理解我的模糊描述(这是由于我对git的了解有限),并知道最佳解决方案。 解决方案

p>在Web服务器上的裸回购上安装一个post-receive钩子会更容易。

这样,这个钩子可以:




  • 更改目录并将新更改提供给实际的非裸回购

  • 结账您想要的分行

  • UL>

    请参阅 GIT中后接收Hook进行网站分段使用Git管理网站

      $ mkdir /var/www/www.example.org 
    $ cat>钩/后收到
    #!/ bin / sh的
    GIT_WORK_TREE = /无功/网络/ www.example.org git的结帐-f
    $使用chmod + X钩/后收到

    (注意:有趣的是,您可以同时推送到两个不同的远程回购站

    Summary: I want to edit files locally, then push to both Github and my web server.

    I have the two remotes set up without issue, so right now I am sort of able to do this; however, I have to have branch A checked out locally, and branch B on the server. Then I have to SSH into the server and check out branch A (the one I want). I really don't even want or need a second branch, but many posts suggest that you can't or shouldn't push to a non-bare repository. There must be a better way. Even just using rsync would be easier than this (and I did it for a while).

    Strangely, this never happens on Github. Almost all my repos only have one branch and I've never gotten this warning.

    The warning message says that you can set receive.denyCurrentBranch to ignore, but I don't know how safe/sane it is. I'm hoping someone will understand my vague description (which is due to my limited knowledge of git) and know the optimum solution.

    解决方案

    It would be easier to set-up a post-receive hook on a bare repo on your web server.
    That way, this hook can:

    • change directory and pull the new changes to the actual non-bare repo
    • checkout the branch you want

    See "Git Post-Receive Hook for Website Staging" and the work in "Using Git to manage a web site":

    $ mkdir /var/www/www.example.org
    $ cat > hooks/post-receive
    #!/bin/sh
    GIT_WORK_TREE=/var/www/www.example.org git checkout -f
    $ chmod +x hooks/post-receive
    

    (Note: fun fact, you can push to two different remote repos simultaneously)

    这篇关于推送到远程服务器和Github的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆