When working with Git and you run git pull
sometimes this error message occurs.
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-to=<remote>/<branch> mybranch
Note: In the last line mybranch
will likely be a different value, this is the name of the current branch you are on.
The Quick Fix
Over 99% of the time running the following corrects this problem for me.
git branch --set-upstream-to=origin/$(git rev-parse --abbrev-ref HEAD)
I even have a git alias to run this command. After this, git pull
should work successfully.
What is the Problem
Why does the “There is no tracking information for the current branch.” error occur in the first place?
When you run git pull
, Git tries to pull any changes from the remote copy of the branch (on a server like GitHub, GitLab, or Bitbucket) into your local branch. The “There is no tracking information for the current branch.” occurs when Git doesn’t know which branch on the server it should pull from.
Almost always you want to pull from the branch on the server origin
with the same name as your local branch (mybranch
). The Quick Fix above sets Git to do exactly this.
When you run the quick fix, it adds the following to your project .git/config
file
[branch "mybranch"]
remote = origin
merge = refs/heads/mybranch
Create Alias
If you run the following line on the command line, it will create a Git alias.
git config --global alias.track-origin-same-branch-name '!git branch --set-upstream-to=origin/$(git rev-parse --abbrev-ref HEAD)'
Then in the future you can run git track-origin-same-branch-name
and your current branch will be set to track the branch with the same name on the origin
remote.
Slightly Longer Fix You Can Memorize
While I’m sure you enjoy visiting this webpage, if you want to be able to solve this issue without referring to instructions this set of steps does the same thing as the one-line quick fix but is easier to remember.
- Copy the last line of the error message.
git branch --set-upstream-to=<remote>/<branch> mybranch
Instead ofmybranch
the last section will be the name of your current Git branch - Using the arrows and Backspace key, replace
<remote>/<branch>
from the middle of the command withorigin/
, the result should look something like
git branch --set-upstream-to=origin/mybranch
- Hit
Enter
Git config push.autoSetupRemote
Git version 2.38
, released 2022-10-03, introduces the push.autoSetupRemote
. Setting this value to true
, makes every git push
act like git push --set-upstream
, which means the first time you push the branch to the remote server it will set the tracking information for your local branch to point to the remote branch.
I’m a big fan of this setting and you can enable it by running the following from the command line
git config --global push.autoSetupRemote true
For me, your solution does not work always:
git branch –set-upstream-to=origin/$(git branch –show-current)
but it works if you change it to:
git branch –set-upstream-to=origin/$(git rev-parse –abbrev-ref HEAD)
https://github.com/six2dez/reconftw/issues/343
You’re right Looping, the
git branch --show-current
command was only introduced in Git 2.22.0, which was released 2019-06-07. If you’re running an older version of Git, this command will fail and as you mentioned you’ll need to usegit rev-parse --abbrev-ref HEAD
instead.Thanks for calling this out.
I’ve updated this article to use
git rev-parse --abbrev-ref HEAD
instead ofgit branch --show-current
for better backwards compatibility.thanks for saving a beginner!