简体   繁体   中英

How to push a GitHub branch to server

On my project I created a new branch called dev and want to push that branch to server but it seems to keep pushing the master branch.

GitHub:

  • Two GitHub branches: Master and Dev

On the server:

  • I have a production site: example.com
  • and a staging site: dev.example.com

My workflow:

  1. I work locally then push to GitHub Dev
  2. Then push to Staging site: dev.example.com so I can test live
  3. Once testing is done I merge Dev to Master and push Master to Production.

Thats what I want to do.

I'm currently stuck pushing the Dev branch to the Staging server: dev.example.com

Here is my local git config file:

[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

Over on my server I have a repo directory: with dev.git & site.git

After I push to my Dev Branch I run git push staging to push to my dev.example.com, but it seems to push my Git Master branch instead.

This is what is in my dev.git/hooks/post-receive file:

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

This is in my site.git/hooks/post-receive file:

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

I'm sure I'm missing something simple, but any help would be appreciated.

Let me recommend the following branch configuration:

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

and the following remote refspec config:

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

On the server side I recommend to check in the hooks what remotes are being updated; post-receive hook is fed with the list on the standard input so add the check to your hooks:

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

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