git pull是针对当前分支还是所有分支?

假如本地又3个分支,对应的3个远程分支都不同步了
那么执行git pull
是将当前本地分支更新
还是所有分支都更新
如果所有分支都更新
如何只针对当前分支?

阅读 18.2k
4 个回答

学会看文档 man git-pull

DESCRIPTION
       Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.
       
       More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. With --rebase, it runs git rebase instead of git merge.

可以看到:

  1. 变更合并到当前分支
  2. 默认情况等价于 git fetch + git merge FETCH_HEAD(有默认自然有其他选项,这些要继续看文档)

其他分支会怎样?因为执行了 git fetch,其他分支的信息会拉取回来,但没有合并,所以会看到和远端的差异:

$ git checkout other-branch
Your branch is behind 'origin/other-branch' by 4 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

自己实践,看文档,可能比 SF 提题要快。

git pull [options] [<repository> [<refspec>…]]

没有指定分支名,默认pull当前分支

只针对当前分支,只会拉当前的分支,这种东西一次性更新所有分支,万一有冲突,够你吃一壶。所以基本都是只更新当前分支

当前分支,最好切换分支之后都pull一下

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题