search

Home  >  Q&A  >  body text

从github上pull一个本地不存在的分支的方法?

github分支结构

本地代码的结构

现在我想从github中pull其develop分支,想达到本地也有master和develop分支的效果,但是我用

git pull origin develop

发现这条命令的结果是在本地的master分支基础上对github的develop分支进行合并

问题1:难道需要现在本地创建一个develop分支,然后checkout到本地develop分支,然后再执行git pull操作吗?如果是这样,那么如果本地分支的个数和github上相差很大时,需要每个都按照上面的方法走一遍?

问题2:有没有一条命令,能对本地的所有分支进行更新同步到github上面的版本?

问题3:有没有方法,能把所有的github的分支更新pull下来?

问题4:如果是本地存在某个分支test,而github上面不存在该分支,是不是需要人工删除?有没有像问题3中把所有分支更新pull下来,包括已删除的分支pull到本地之后,本地的相应分支也会删除

ringa_leeringa_lee2807 days ago533

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-24 09:13:39

    1. Correspondence of git fetch origin 取远程的变更即可。或者 git pull 取当前分支的更新的同时会把其它分支也拖回来的。除非 clone 的时候用了 -b 选项。你也可以用 git fetch origin develop 来指定。git fetchgit push.
    2. You are too lazy. man git-push You can see the answer (well, even though I didn’t know it before):

    --all
    Instead of naming each ref to push, specifies that all refs under refs/heads/ be pushed.

    reply
    0
  • 阿神

    阿神2017-04-24 09:13:39

    • If you only want to synchronize the remote repository to the local one:
    $ git fetch origin
    
    • If you want to pull down certain content in the remote branch after completing the synchronization of the remote repository. Think about it carefully, git pull就是分为git fetchgit mergeIt is implemented by two commands, the former operates the repository, and the latter affects local files through the repository. Well, you can
    $ git checkout -b localbranch
    $ git pull origin remotebranch:localbranch // 当本地分支和远程分支名称相同时,只写一个就可以
    // 这种方法适合pull指定分支
    
    • You need to push all local branches to the remote end
    $ git push -all
    

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-24 09:13:39

    Understand git pull = fetch + merge, then question 3 cannot be done, because merge may have conflicts and can only operate one branch.

    I also hate English manuals, they are hard to read. . .

    reply
    0
  • Cancelreply