zoukankan      html  css  js  c++  java
  • Git Pull Request 协作式开发流程

    pull request 协作式开发流程

    优点:

    • 主仓库自己只有管理员有权限修改,安全;合并代码之前管理员可以进行审核;
    • 每个开发者有自己的远程仓库,可以随时push代码而不影响协作者;

    流程

    1. fork 自己的仓库

    在前端页面点击fork按钮。

    假设公共仓库地址为 git@git.chengfayun.net:Public/some-project.git
    fork后自己的仓库地址为 git@git.chengfayun.net:aloe/some-project.git

    2. git clone 自己的仓库到本地

    git clone git@git.chengfayun.net:aloe/some-project.git
    
    cd some-project
    

    输入命令git remote -v查看remote,结果如下:

    origin	git@git.chengfayun.net:aloe/some-project.git (fetch)
    origin	git@git.chengfayun.net:aloe/some-project.git (push)
    

    可以看到本地仓库只和自己的远程仓库进行了关联,这样无法获取公共仓库的最新代码,下一步需要添加本地仓库和公共仓库的关联。

    3. 添加本地仓库和公共仓库的关联

    git remote add upstream 公共仓库地址(本例中为 git@git.chengfayun.net:Public/some-project.git)

    再次输入命令git remote -v查看remote,结果如下:

    origin	git@git.chengfayun.net:aloe/some-project.git (fetch)
    origin	git@git.chengfayun.net:aloe/some-project.git (push)
    upstream	git@git.chengfayun.net:Public/some-project.git (fetch)
    upstream	git@git.chengfayun.net:Public/some-project.git (push)
    

    4. 本地开发

    1. 修改代码;
    2. git add 暂存;
    3. git commit 提交;

    5. 拉取公共仓库最新代码

    目地:合并其他开发者的提交

    执行命令 git pull upstream master

    6. 将提交推送到自己的远程仓库

    执行命令 git push,该命令省略了remote和branch,完整命令为git push 关联remote 关联分支名

    如何查看默认关联的remote和branch? 执行git branch -vv命令,结果如下:

    *  master  bdbfefc [origin/master] ***
    

    7. 提merge request

    登录自己的远程仓库,点击 create merge request 按钮新建merge request,这时公共仓库会显示有merge request待合并。

    8. 管理员合并merge request

    公共仓库增加了分支怎么办

    执行命令 git checkout -b new-branch upstream/new-branch后本地会增加new-branch分支。

    执行git branch -vv查看新分支的关联关系如下:

      dev      bdbfefc [origin/dev]  ****
    * new-branch eef4796 [upstream/new-branch]  ***
    

    可以看到new-branch是和公共仓库关联的,为了和之前的开发方式保持一致,需要将默认remote改为自己的远程仓库。

    1. 执行git push origin new-branch将新分支推到自己的远程仓库;

    2. 执行git branch -u origin/new-branch new-branch将新分支的默认关联设为自己的远程仓库;

    输入 git branch -vv再次查看,大功告成!

      dev      bdbfefc [origin/dev]  ****
    * new-branch eef4796 [origin/new-branch]  ***
    
  • 相关阅读:
    五秒自动刷新页面
    浅析MySQL中exists与in的使用 (写的非常好)
    基于shiro授权过程
    shiro认证
    jsp中<c:if>与<s:if>的区别
    链表数据结构相关
    队列Queue中add()和offer()的区别?
    Java中有几种线程池?
    解决idea使用jstl标签报错和不自动提示
    事务
  • 原文地址:https://www.cnblogs.com/aloe-n/p/11127582.html
Copyright © 2011-2022 走看看