921

I've been using github from a relatively short period, and I've always used the client to perform commits and pulls. I decided to try it from the git bash yesterday, and I successfully created a new repo and committed files.

Today I did changes to the repository from another computer, I've committed the changes and now I'm back home and performed a git pull to update my local version and I get this:

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 develop origin/<branch>

the only contributor to this repo is me and there are no branches (just a master). I'm on windows and I've performed the pull from git bash:

enter image description here

git status:

$ git status
# On branch master
nothing to commit, working directory clean

git branch:

$ git branch
* master

What am I doing wrong?

Liam
  • 27,717
  • 28
  • 128
  • 190
valerio0999
  • 11,458
  • 7
  • 28
  • 56
  • 1
    Okay, how about a `git remote -v`? What does that say? – criswell Aug 17 '15 at 17:58
  • 1
    Possible duplicate of [git checkout tag, git pull fails in branch](http://stackoverflow.com/questions/10147475/git-checkout-tag-git-pull-fails-in-branch) – rjmunro Feb 18 '16 at 16:33
  • 1
    You can also get that error if you have not cd into the cloned repo directory, when executing `git pull`. – Victoria Stuart Apr 23 '18 at 15:30
  • 1
    With Git 2.24, Q4 2019, `git pull --set-upstream-to=origin/master master` is possible. See [my answer below](https://stackoverflow.com/a/57999939/6309) – VonC Sep 18 '19 at 19:58
  • Use `git pull origin master --allow-unrelated-histories` https://www.educative.io/edpresso/the-fatal-refusing-to-merge-unrelated-histories-git-error – JVJplus Aug 05 '21 at 07:28

17 Answers17

1429

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.

ComputerDruid
  • 16,897
  • 1
  • 19
  • 28
  • 7
    perfect! it worked. so what happened is there was no "default branch" for a default "git pull"? that's why there was the error? – valerio0999 Aug 17 '15 at 17:35
  • 36
    --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. – Bart Read Sep 30 '15 at 08:21
  • 9
    @BartRead updated it to use the new clearer `--set-upstream-to=` syntax. (which is the replacement for `--set-upstream`) – ComputerDruid Oct 12 '15 at 21:00
  • 110
    this seems like a sorry state of affairs - do we really need to set this manually for every branch? Why can't we just set origin to be the default remote and then have every push/pull default to the branch on origin with the same name? is this so hard? – Alexander Mills Dec 09 '15 at 20:04
  • 7
    Ah, the key part for me here was that if you drop and re-create a remote then the tracking that was set up by the original `fetch` has been lost. Hence the need to set it up again. :) – Ben Mar 23 '16 at 09:01
  • 1
    A little more information about tracking information would be perfect. What is it tracking anyways, and how is it used? – NeoJi Jun 13 '16 at 13:45
  • 1
    @NeoJi - You can check section "Tracking Branches" at https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches – nanosoft Dec 15 '17 at 07:23
  • 2
    to see where origin is pointing at, you can use "git remote -v" . "-v" stands for verbose. – Onat Korucu Mar 12 '20 at 07:31
  • Well then you can get `fatal: refusing to merge unrelated histories`. – Ben Racicot Oct 22 '20 at 14:02
  • getting fatal: branch 'master' does not exist. Why? – Jürgen K. Oct 28 '20 at 20:21
  • @JürgenK. The branch is likely no longer named 'master'. You should try the newer naming convention 'main'. – s3c Jun 20 '21 at 16:44
  • This works. Only need to change to `git branch --set-upstream-to=origin/main main` `git pull` – Xiaorui Zhu Sep 12 '21 at 05:04
  • There is command `git config --global push.default current` to push current branch, shorten it to just` git push` – D4ITON Nov 30 '21 at 11:49
  • I created a different branch and I want to pull from the master but it says already up to date as I know that there are some commits that are ahead in the master branch. can anyone guide me as I am not expert in git – djangodeveloper Feb 06 '22 at 19:08
  • Its ```git pull origin main``` now – heysujal Jul 28 '23 at 07:56
75

See: git checkout tag, git pull fails in branch

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..., run:

 git set-upstream
 git push

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

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
rjmunro
  • 27,203
  • 20
  • 110
  • 132
  • 11
    Here's a way to add it to the global `.gitconfig` in one line (can be modified for local or other configs accordingly): `git config --global alias.set-upstream '!git branch --set-upstream-to=origin/$(git symbolic-ref --short HEAD)'` – Danny Bullis Jul 15 '19 at 20:46
  • ha - I tried this, and it still says the upstream branch doesn't exist (it does, and yes, I didn't mispell it - pun intended) – J. Gwinner Aug 22 '22 at 23:52
  • Trying such alias `[alias] cr = "!f() { git switch -c $1; git branch --set-upstream-to=origin/$1 $1; }; f"` but receive `error: the requested upstream branch 'origin/test' does not exist` – Vitaly Zdanevich Sep 26 '22 at 11:28
  • 3
    A "modern" equivalent to this in git 2.37+ is to set `git config --global branch.autoSetupMerge simple` (so you only get automatic tracking on same-name bran ches, and new-name branches are "independent"), and also `git config --global push.autoSetupRemote true` (so when you do `git push` on a new independent branch, it automatically pushes your new branch to the remote, and sets up tracking to the remote branch. That way you never *need* to `git set-upstream`, you can just branch, pull and push as you would expect, and things will work for same-name remote branches. – Tao Jan 13 '23 at 15:49
46

ComputerDruid's answer is great but I don't think it's necessary to set upstream manually unless you want to. I'm adding this answer because people might think that that's a necessary step.

This error will be gone if you specify the remote that you want to pull like below:

git pull origin master

Note that origin is the name of the remote and master is the branch name.


1) How to check remote's name

git remote -v

2) How to see what branches available in the repository.

git branch -r
aerin
  • 20,607
  • 28
  • 102
  • 140
32

Step 1

$ git pull
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> master

Step 2

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

Step 3

$ git pull
Already up to date.
Coconut
  • 2,024
  • 18
  • 25
24

For anyone who wants to understand why this happens, there are a few relevant concepts:

  • A git repository can have zero or more "remotes", which are named links to other repositories, usually on some central server somewhere. You can list them with "git remote -v"
  • If you clone a repository from another server, a default remote called "origin" will be set up for you.
  • The full syntax for both git push and git pull is to specify a remote name and a branch on that remote.
  • A local branch can be associated with a branch on a remote, so that you don't have to type it each time you pull or push.
  • If you check out a branch from a remote repository using "git switch branchname" or "git switch -u origin/branchname", the association will be set for you. ("git switch" is the same in this case as "git checkout")
  • If you create a branch locally and then push it with git push -u origin, it will set the association.
  • But if you don't include the -u in the initial pull or push, the association won't be stored, so you have to be specific every time.

The solution, as other answers point out, is to set the association with git branch --set-upstream-to=origin/branchname, where origin is the name of the remote, and "branchname" is what the branch is called on the remote server. That's probably the same name it has locally, but it doesn't have to be.

Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • 3
    I don't understand, what is the downside of having default behaviour of always setting upstream branch when you are pushing a new one to remote? You did not explain why it's need to manage this explicitly each time. Why it wasn't added a config option for this? – warvariuc Mar 24 '22 at 07:50
  • @warvariuc That's a different kind of "why", and one I'm not qualified to answer because I have never been involved in the development of git. Part of the answer is probably that git was designed to be completely decentralised, so having a single "central" copy somewhere like Github isn't what they were originally optimising for. If you've got three different remotes you might push the same branch to, setting the tracking to whichever you push to first would be really confusing. – IMSoP Mar 24 '22 at 08:46
  • 1
    Thanks for the answer. During my 10 years working with Git and different teams, I very rarely had several remotes. Also not having an option to configure the behavior is strange. So I am trying to find out the reason and way to persuade the devs to add the configuration option... – warvariuc Mar 25 '22 at 09:57
  • Most helpful bit: `if you don't include the -u in the initial pull or push...`. That's been my problem for years without knowing it. – CrashNeb Aug 04 '23 at 21:57
21

With Git 2.24 (Q4 2019), you won't have to do

git branch --set-upstream-to=origin/main main
git pull

You will be able to do:

git pull --set-upstream-to=origin/main main

See more at "default remote and branch using -u option - works with push but not pull".


Note that with Git 2.37 (Q3 2022), you have a new option push.autoSetupRemote

git config --global push.autoSetupRemote true

Then a simple git push would be the same as git push --set-upstream-to=origin/main main, making the next git pull already set to retrieve commits from origin/main.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
14

I was trying the above examples and couldn't get them to sync with a (non-master) branch I had created on a different computer. For background, I created this repository on computer A (git v 1.8) and then cloned the repository onto computer B (git 2.14). I made all my changes on comp B, but when I tried to pull the changes onto computer A I was unable to do so, getting the same above error. Similar to the above solutions, I had to do:

git branch --set-upstream-to=origin/<my_branch_name> 
git pull

slightly different but hopefully helps someone

imapotatoe123
  • 656
  • 1
  • 10
  • 21
13

This happens due to current branch has no tracking on the branch on the remote. so you can do it with 2 ways.

  1. Pull with specific branch name

    git pull origin master

  2. Or you can specific branch to track to the local branch.

    git branch --set-upstream-to=origin/<branchName>

Swaroop Maddu
  • 4,289
  • 2
  • 26
  • 38
KR93
  • 1,098
  • 11
  • 10
10

I run into this exact message often because I create a local branches via git checkout -b <feature-branch-name> without first creating the remote branch.

After all the work was finished and committed locally the fix was git push -u which created the remote branch, pushed all my work, and then the merge-request URL.

Ron Reynolds
  • 544
  • 5
  • 10
  • 3
    for what it's worth, I had to run `git push -u origin ` in order to create the remote branch and push my work – Donnie C Jan 21 '19 at 06:10
9

This answer is best for

who is looking to link their repo to their project and commit changes

As per coconut`s answer

Step 1

git pull
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> master

Step 2

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

Step 3

git pull
Already up to date.

The Problem

I spent several hours while committing my changes I followed the steps above And git add . git commit . Then i executed the steps below and my push was succesful

To push changes

execute

git push -f origin master
Arnav Singh
  • 194
  • 2
  • 4
7

try

   git pull --rebase

hope this answer helps originally answered here https://stackoverflow.com/a/55015370/8253662

Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
6

Try using

git push --set-upstream origin <branch_name>

Otherwise

use

git push -u 

will tell you what needs to be done.

Gopalakrishnan T
  • 453
  • 1
  • 4
  • 14
  • git branch --set-upstream origin BRANCH_NAME_HERE fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead. – demented hedgehog Mar 09 '22 at 21:26
4

1) git branch --set-upstream-to=origin/<master_branch> feature/<your_current_branch>

2) git pull

MERLIN THOMAS
  • 747
  • 1
  • 7
  • 15
2

The same thing happened to me before when I created a new git branch while not pushing it to origin.

Try to execute those two lines first:

git checkout -b name_of_new_branch # create the new branch
git push origin name_of_new_branch # push the branch to github

Then:

git pull origin name_of_new_branch

It should be fine now!

Newt
  • 787
  • 8
  • 15
2

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

Swaroop Maddu
  • 4,289
  • 2
  • 26
  • 38
  • 7
    It is always helpful add some explanation to your answer, to make it more clear and understandable. Please read https://stackoverflow.com/help/how-to-answer. – 32cupo Jun 02 '20 at 09:36
  • 1
    In addition to @32cupo’s point, this is essentially the same as the five year old accepted answer, but with less explanation. – Jeremy Caney Jun 03 '20 at 05:20
  • If I am working on a branch that is on the origin, will this break anything? – AgilePro Apr 21 '21 at 05:34
1

$ git branch --set-upstream-to=heroku/master master and

$ git pull

worked for me!

Maya
  • 75
  • 1
  • 3
0

Like @Alexander Mills pointed out in a comment above, it's pretty annoying there isn't a command to automatically set all future tracking information, to the same origin name + current branch name, without having to push first. In many cases you cannot even push first due to pull request protection which makes sense.

The easiest solution for me personally is again, using aliases or in other words shortcut macros. There is a command to gain the current branch name. I run git from command line with cygwin and this is how I had to insert it into my .bashrc file (not .gitconfig) for my aliases to work:

alias track='git branch --set-upstream-to=origin/$(git symbolic-ref --short HEAD)'

So now I can just call 'track' to set up the damn tracking information on every branch.

Alex Mm
  • 65
  • 1
  • 1
  • 7