git checkout tag, git pull fails in branch

后端 未结 14 570
渐次进展
渐次进展 2021-01-29 22:51

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<

相关标签:
14条回答
  • 2021-01-29 23:17

    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.

    0 讨论(0)
  • 2021-01-29 23:20

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

    git branch --track
    

    After that this works again:

    git pull
    
    0 讨论(0)
  • 2021-01-29 23:21

    @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.
    
    0 讨论(0)
  • 2021-01-29 23:21

    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

    0 讨论(0)
  • 2021-01-29 23:23

    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.

    0 讨论(0)
  • 2021-01-29 23:26

    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.

    0 讨论(0)
提交回复
热议问题