簡體   English   中英

如何將GitHub分支推送到服務器

[英]How to push a GitHub branch to server

在我的項目中,我創建了一個名為dev的新分支,並希望將該分支推送到服務器,但它似乎繼續推動主分支。

GitHub的:

  • 兩個GitHub分支:Master和Dev

在服務器上:

  • 我有一個生產網站:example.com
  • 和暫存站點:dev.example.com

我的工作流程

  1. 我在本地工作然后推送到GitHub Dev
  2. 然后推送到Staging site:dev.example.com,這樣我就可以進行實時測試了
  3. 測試完成后,我將Dev合並到Master並將Master推送到Production。

多數民眾贊成我想做的事。

我目前無法將Dev分支推送到Staging服務器:dev.example.com

這是我的本地git配置文件:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[branch "origin"]
    remote = git@github.com:xxxx/xxxxxxxx.git
    merge = refs/heads/master

[remote "origin"]
    url = git@github.com:daugaard47/povertyresolutions.git
    fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]
    remote = origin
    merge = refs/heads/master

[remote "production"]
    url = ssh://root@140.xx.xx.xx/var/repo/site.git
    fetch = +refs/heads/*:refs/remotes/production/*

[remote "staging"]
    url = ssh://root@140.xx.xx.xx/var/repo/dev.git
    fetch = +refs/heads/*:refs/remotes/dev/*

[branch "dev"]
    remote = staging
    merge = refs/heads/dev

在我的服務器上,我有一個repo目錄: dev.gitsite.git

在我推送到我的Dev Branch我運行git push staging來推送到我的dev.example.com,但它似乎推動了我的Git Master分支。

這是我的dev.git/hooks/post-receive文件中的內容:

#!/bin/sh
git --work-tree=/var/www/dev --git-dir=/var/repo/dev.git checkout -f

這是在我的site.git/hooks/post-receive文件中:

#!/bin/sh
git --work-tree=/var/www/laravel --git-dir=/var/repo/site.git checkout -f

我確定我錯過了一些簡單的東西,但任何幫助都會受到贊賞。

我建議使用以下分支配置:

git config branch.master.remote production
git config branch.dev.remote staging

和以下遠程refspec配置:

git config remote.production.push refs/heads/master:refs/remotes/production/master
git config remote.staging.push refs/heads/dev:refs/remotes/staging/dev

在服務器端,我建議檢查鈎子正在更新哪些遙控器; post-receive hook 用標准輸入上的列表提供,所以將檢查添加到你的鈎子:

while read old_hash new_hash ref; do
    if [ "$ref" = refs/heads/master ]; then
        git … checkout …
    fi
done

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM