Home Tags About

Git: 如何在 pull/push 时避免输入 remote branch name

30 Oct 2012

有时在 git pull 时(push 也类似,这里以 pull 为例),会出现如下情况:

You asked me to pull without telling me which branch you want to merge with, and ‘branch.master.merge’ in your configuration file does not tell me, either. Please specify which branch you want to use on the command line and try again (e.g. ‘git pull '). See git-pull(1) for details.

这是因为由于某种原因,git 没有为你自动匹配到默认的远程分支,这时你需要完整的输入远程分支名才能完成命令: git pull origin master

但是如果经常需要对这个远程分支做合并操作,每次这样输入就显得比较繁琐了。我们可以使用如下命令,来为本地的 “master” 分支设置 “upstream”,这样以后就能自动匹配了:

git branch --set-upstream master origin/master

下次再合并 “origin/master” 时,就只需简单的执行 git pull 了。