git checkout tag, git pull fails in branch

GitGit PullGit Checkout

Git Problem Overview


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 > > If you wish to set tracking information for this branch you can do so > with: > > git branch --set-upstream new origin/

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..

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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).

Solution 3 - Git

Try these commands:

git pull origin master
git push -u origin master

Solution 4 - Git

Switch back to the master branch using

$ git checkout master

and then run the git pull operation

$ git pull origin/master

Afterwards, you can switch back to your my_branch again.

Solution 5 - Git

@alesko : it is not possible to only do only git pull after checkout my_branch to update master branch only.
Because git pull will also merge to the current branch -> in your scenario to the my_branch

@Simon: that will do also the push. why is that?

$ git branch -u origin/master
Branch master set up to track remote branch master from origin.

and acording to docs:

-u <upstream>
  Set up <branchname>'s tracking information so <upstream> is considered  
  <branchname>'s upstream branch. If no <branchname> is specified,  
  then it defaults to the current branch.

Solution 6 - Git

First, make sure you are on the right branch.
Then (one time only):

git branch --track

After that this works again:

git pull

Solution 7 - Git

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.

Solution 8 - Git

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

Solution 9 - Git

If like me you need to do this all the time, you can set up an alias to do it automatically by adding the following to your .gitconfig file:

[alias]
    set-upstream = !git branch --set-upstream-to=origin/`git symbolic-ref --short HEAD`

When you see the message There is no tracking information..., just run git set-upstream, then git push again.

Thanks to https://zarino.co.uk/post/git-set-upstream/

Solution 10 - Git

Try this

git checkout master

git pull origin master

Solution 11 - Git

You need to set up your tracking (upstream) for the current branch

git branch --set-upstream master origin/master

Is already deprecated instead of that you can use --track flag

git branch --track master origin/master

I also like the doc reference that @casey notice:

-u <upstream>
  Set up <branchname>'s tracking information so <upstream> is considered  
  <branchname>'s upstream branch. If no <branchname> is specified,  
  then it defaults to the current branch.

Solution 12 - Git

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.

Solution 13 - Git

In order to just download updates:

git fetch origin master

However, this just updates a reference called origin/master. The best way to update your local master would be the checkout/merge mentioned in another comment. If you can guarantee that your local master has not diverged from the main trunk that origin/master is on, you could use git update-ref to map your current master to the new point, but that's probably not the best solution to be using on a regular basis...

Solution 14 - Git

This command is deprecated: git branch --set-upstream master origin/master

So, when trying to set up tracking, this is the command that worked for me:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaleskoView Question on Stackoverflow
Solution 1 - GitVincent WenView Answer on Stackoverflow
Solution 2 - GitSimon Raik-AllenView Answer on Stackoverflow
Solution 3 - GitnavinsView Answer on Stackoverflow
Solution 4 - GitcfedermannView Answer on Stackoverflow
Solution 5 - GitCaseyView Answer on Stackoverflow
Solution 6 - GitdrzymalaView Answer on Stackoverflow
Solution 7 - GitEricView Answer on Stackoverflow
Solution 8 - GitAkash KandpalView Answer on Stackoverflow
Solution 9 - GitrjmunroView Answer on Stackoverflow
Solution 10 - GitvanarajcsView Answer on Stackoverflow
Solution 11 - GitJorman BustosView Answer on Stackoverflow
Solution 12 - GitJason DView Answer on Stackoverflow
Solution 13 - GittwalbergView Answer on Stackoverflow
Solution 14 - GitAaron LelevierView Answer on Stackoverflow