Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout tag, git pull fails in branch

People also ask

Does git pull work on branches?

git pull is a Git command used to update the local version of a repository from a remote. It is one of the four commands that prompts network interaction by Git. By default, git pull does two things. Updates the remote tracking branches for all other branches.

Can you git checkout a tag?

In order to checkout a Git tag, use the “git checkout” command and specify the tagname as well as the branch to be checked out. Note that you will have to make sure that you have the latest tag list from your remote repository.

How do you checkout and pull a branch?

Git checkout works hand-in-hand with git branch . The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

Why does git pull Fail?

It means that: You locally have those files, and you haven't versioned them. Those files are tracked in the master of the remote repository.


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.


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

Try these commands:

git pull origin master
git push -u origin master

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.


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

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

git branch --track

After that this works again:

git pull