• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Dev Tips / There is no tracking information for the current branch.

There is no tracking information for the current branch.

Last updated on November 12, 2022 by Sal Ferrarello

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.

  1. Copy the last line of the error message.
    git branch --set-upstream-to=<remote>/<branch> mybranch
    Instead of mybranch the last section will be the name of your current Git branch
  2. Using the arrows and Backspace key, replace <remote>/<branch> from the middle of the command with origin/, the result should look something like
    git branch --set-upstream-to=origin/mybranch
  3. 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
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Solution Tagged With: Git

Reader Interactions

Comments

  1. Looping says

    October 3, 2022 at 8:35 am

    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

    Reply
    • Sal Ferrarello says

      October 16, 2022 at 10:11 pm

      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 use git rev-parse --abbrev-ref HEAD instead.

      Thanks for calling this out.

      Reply
      • Sal Ferrarello says

        November 12, 2022 at 4:09 am

        I’ve updated this article to use git rev-parse --abbrev-ref HEAD instead of git branch --show-current for better backwards compatibility.

        Reply
  2. lovefrom says

    December 9, 2022 at 11:57 am

    thanks for saving a beginner!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in