When executing git pull or git push, the following error messages sometimes appear:
$ git pull You asked me to pull without telling me which branch you want to merge with, and 'branch.linux_c++.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 <repository> <refspec>'). See git-pull(1) for details. If you often merge with the same branch, you may want to use something like the following in your configuration file: [branch "linux_c++"] remote = <nickname> merge = <remote-ref> [remote "<nickname>"] url = <url> fetch = <refspec> See git-config(1) for details.
Let’s first look at the current branch status:
$ git branch -av * linux_c++ 584efea add cscope and fix fileencoding problam master ee9d037 v1.0.1: add install.sh remotes/origin/HEAD -> origin/master remotes/origin/linux_c++ 584efea add cscope and fix fileencoding problam remotes/origin/master ee9d037 v1.0.1: add install.sh
Current Linux_C + + branch and remote Linux_C + + has the same name, but in fact, this branch is not origin/Linux_The tracking branch of C + + branch, so when git pull is directly used to request to pull a new branch, GIT does not know which branch to pull
Therefore, there are two solutions to this problem. One is to specify the corresponding remote branch name when git pull or git push, such as:
$ git pull origin linux_c++
Another scheme is to set the current branch to track a remote branch. There are two ways to set an existing branch to track a remote branch:
git branch -u remote-name/branch_name branch_name
Or
git branch --set-upstream-to=remote_name/branch_name branch_name
Of course, when you create a local branch, you can directly trace it to the remote branch:
git checkout -b local_branch remote_name/remote_branch
currently our branches are existing branches, so we can input:
$ git branch -u origin/linux_c++ linux_c++ Branch linux_c++ set up to track remote branch linux_c++ from origin.
It should be noted that git branch – U and git branch — The two options of set upstream to are available only in the higher git version. At least bloggers find that they are not available in 1.7.1, but they are available in 1.8.3.1