zoukankan      html  css  js  c++  java
  • git如何从远程非master分支更新到本地对应分支

    git如何从远程非master分支更新到本地对应分支

    自己实例

    正确步骤

    如果本地有分支,那就删除本地分支

    删除本地分支::git branch -d 2018_4_18_second

    切换分支: git checkout master

    将远程分支 上的东西拉下来: git checkout -b 2018_4_18_second origin/2018_4_18_second

    # 列出所有本地分支$ git branch
    # 列出所有远程分支$ git branch -r
    # 列出所有本地分支和远程分支$ git branch -a
    # 新建一个分支,并切换到该分支$ git checkout -b [branch]

    拉文件下来的话

    git pull https://github.com/fry404006308/m_Orchestrate.git 2018_4_18_second

    或者试试

    git pull

    善于使用帮助命令,特别好用

    从帮助命令知道怎么弄,超级快

    git help pull

    然后你会看到这样的示例用法:

     1 EXAMPLES
     2 Update the remote-tracking branches for the repository you cloned from, then merge one of them into your current branch:
     3 
     4 $ git pull
     5 $ git pull origin
     6 Normally the branch merged in is the HEAD of the remote repository, but the choice is determined by the branch.<name>.remote and branch.<name>.merge options; see git-config(1) for details.
     7 
     8 Merge into the current branch the remote branch next:
     9 
    10 $ git pull origin next
    11 This leaves a copy of next temporarily in FETCH_HEAD, but does not update any remote-tracking branches. Using remote-tracking branches, the same can be done by invoking fetch and merge:
    12 
    13 $ git fetch origin
    14 $ git merge origin/next
    15 If you tried a pull which resulted in complex conflicts and would want to start over, you can recover with git reset.

    所以就知道怎么弄了

    将远程git仓库里的指定分支拉取到本地(本地不存在的分支)

    当我想从远程仓库里拉取一条本地不存在的分支时:

    git checkout -b 本地分支名 origin/远程分支名

    这个将会自动创建一个新的本地分支,并与指定的远程分支关联起来。

    例如远程仓库里有个分支dev2,我本地没有该分支,我要把dev2拉到我本地:

    若成功,将会在本地创建新分支dev2,并自动切到dev2上。

    如果出现提示:

    fatal: Cannot update paths and switch to branch 'dev2' at the same time.
    Did you intend to checkout 'origin/dev2' which can not be resolved as commit?

    表示拉取不成功。我们需要先执行

    git fetch

    然后再执行

    git checkout -b 本地分支名 origin/远程分支名

    即可。

    git checkout -b 2018_4_18_second

     

    忘记 pull up了 远程建立分支后,要pull up更新一下本地,就可以显示出来了,新手,弄了几个小时,才弄出来。。

    git pull之后,才显示远程分支

    别人实例

    git一般有很多分支,我们clone到本地的时候一般都是master分支,那么如何切换到其他分支呢?主要命令如下:

    1. 查看远程分支

    $ git branch -a 
    我在mxnet根目录下运行以上命令:

    ~/mxnet$ git branch -a
    * master
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
      remotes/origin/nnvm
      remotes/origin/piiswrong-patch-1
      remotes/origin/v0.9rc1
    

    可以看到,我们现在在master分支下

    2. 查看本地分支

    ~/mxnet$ git branch
    * master

    3. 切换分支

    $ git checkout -b v0.9rc1 origin/v0.9rc1
    Branch v0.9rc1 set up to track remote branch v0.9rc1 from origin.
    Switched to a new branch 'v0.9rc1'
    
    #已经切换到v0.9rc1分支了
    $ git branch
      master
    * v0.9rc1
    
    #切换回master分支
    $ git checkout master
    Switched to branch 'master'
    Your branch is up-to-date with 'origin/master'.
     
  • 相关阅读:
    Java笔记06
    Kubernetes V1.16.2部署Dashboard V2.0(beta5)
    安装Kubernetes V1.16.2
    Spring Cloud Stream 进行服务之间的通讯
    通过总线机制实现自动刷新客户端配置(Consul,Spring Cloud Config,Spring Cloud Bus)
    手动刷新客户端配置内容(Spring Cloud Config)
    创建客户端项目并读取服务化的配置中心(Consul + Spring Cloud Config)
    创建配置中心服务端(Spring Cloud Config)
    Consul集群加入网关服务(Spring Cloud Gateway)
    Consul集群Server+Client模式
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/8872269.html
Copyright © 2011-2022 走看看