简体   繁体   English

如何 git pull 在我的开发远程服务器上的特定分支?

[英]How to git pull a specific branch on my development remote server?

I am trying to create a Local -> Development -> Production environment with the help of Git(hub).我正在尝试在 Git(hub) 的帮助下创建一个本地 -> 开发 -> 生产环境。 But I cannot find the right way to do this.但我找不到正确的方法来做到这一点。

These are the levels:这些是级别:

  1. Local development repository with a master, develop and feature branches.具有 master、develop 和 feature 分支的本地开发存储库。
  2. Github repository with master, develop and feature branches.带有 master、develop 和 feature 分支的 Github 存储库。
  3. Test remote server https://test.website.com/测试远程服务器https://test.website.com/
  4. Production server https://website.com/生产服务器https://website.com/

This is the workflow I have in mind:这是我想到的工作流程:

1) I make my changes locally, first in feature branches. 1) 我在本地进行更改,首先是在feature分支中。

2) Merge feature branch with develop branch. 2) 将feature分支与develop分支合并。

3) Push to Github repository. 3) 推送到 Github 存储库。

4) Pull the develop branch to my test remote server. 4)将develop分支拉到我的测试远程服务器。 Test if everything is ok.测试是否一切正常。

// Development server
ssh username@[IP_ADDRESS]
cd /to/my/git/folder
git pull https://www.github.com/user/repo

5) Merge my develop branch into master . 5)将我的 develop 分支合并到master

6) Pull my master branch on my production remote server. 6)在我的生产远程服务器上拉我的master分支。

// Production server    
ssh username@[IP_ADDRESS] 
cd /to/my/git/folder
git pull https://www.github.com/user/repo

The Problem问题

The problem I am facing is that when I git pull my repo on the development server I only get my master branch.我面临的问题是,当我在开发服务器上git pull我的 repo 时,我只能得到我的master分支。 But I want my develop branch on my development server and my master branch on my production server.但是我希望我的develop服务器上的develop分支和生产服务器上的master分支。

Is this even an efficient workflow or do I need to design it another way?这甚至是一个有效的工作流程还是我需要以另一种方式设计它?

In the development server you can do git pull && git checkout <development-branch-name> It will update the git repo with the changes and switch the repo to use the development branch.在开发服务器中,您可以执行git pull && git checkout <development-branch-name>它将使用更改更新 git repo 并切换 repo 以使用开发分支。

Take a look at this question to know how to configure your .gitconfig file to track the remote branch - Git: which is the default configured remote for branch?看看这个问题就知道如何配置你的.gitconfig文件来跟踪远程分支 - Git:这是分支的默认配置远程?

Regarding the workflow, that is how things are done in places that I have worked.关于工作流程,这就是我工作过的地方的工作方式。 So, I guess it seems fine.所以,我想它看起来不错。

I solved the problem as follows:我解决了这个问题如下:

> ssh username@[IP_ADDRESS] 
> cd /to/my/git/folder 
> git init
> git remote add origin https://github.com/user/repo.git
> git pull origin develop

I had to set my remote so I was able to pull the right develop branch.我必须设置我的遥控器,这样我才能拉出正确的开发分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM