git checkout tag, git pull fails in branch

2020-05-11 04:34发布

I have cloned a git repository and then checked out a tag:

# git checkout 2.4.33 -b my_branch

This is OK, but when I try to run git pull in my branch, git spits out this error:

There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream new origin/<branch>

I want git pull to only update the master branch and leave my current branch alone (it's a tag anyway). Is something like this possible?

The reason I need this is that I have a automatic script which always git pulls the repository and of course fails because of the error above..

14条回答
萌系小妹纸
2楼-- · 2020-05-11 04:46

I had the same problem and fixed it with this command:

$ git push -u origin master

From the help file the -u basically sets the default for pulls:

-u, --set-upstream`

  For every branch that is up to date or successfully pushed, add 
  upstream (tracking) reference, used by argument-less git-pull(1) and
  other commands. For more information, see branch.<name>.merge in 
  git-config(1).
查看更多
太酷不给撩
3楼-- · 2020-05-11 04:46

You might have multiple branch. And your current branch didn't set its upstream in remote.

Steps to fix this:

git checkout branch_name
git branch --set-upstream-to=origin/remote_branch_name local_branch_name

e.g.

// this set upstream of local branch develop to remote branch  origin/develop,
git branch --set-upstream-to=origin/develop develop

After doing this, when you do git pull, it pull from specified branch.

查看更多
唯我独甜
4楼-- · 2020-05-11 04:46

You could specify what branch you want to pull:

git pull origin master

Or you could set it up so that your local master branch tracks github master branch as an upstream:

git branch --set-upstream-to=origin/master master
git pull

This branch tracking is set up for you automatically when you clone a repository (for the default branch only), but if you add a remote to an existing repository you have to set up the tracking yourself. Thankfully, the advice given by git makes that pretty easy to remember how to do.

--set-upstream is deprecated in git 1.9.x, apparently. Going forward you'd want to use something like

git branch -u origin/master

assuming you've checked out master already. If not, git branch -u origin/master master will work

查看更多
虎瘦雄心在
5楼-- · 2020-05-11 04:49

Edit: For newer versions of Git, --set-upstream master has been deprecated, you should use --set-upstream-to instead:

git branch --set-upstream-to=origin/master master

As it prompted, you can just run:

git branch --set-upstream master origin/master

After that, you can simply run git pull to update your code.

查看更多
倾城 Initia
6楼-- · 2020-05-11 04:53

What worked for me was: git branch --set-upstream-to=origin master When I did a pull again I only got the updates from master and the warning went away.

查看更多
甜甜的少女心
7楼-- · 2020-05-11 04:55

Try this

git checkout master

git pull origin master
查看更多
登录 后发表回答