81

I am pretty new to git. I have been primarily checking stuff into a repository, but now I want to get the latest changes from another developer.

I tried to simply do a command like git pull something ran, but it came back with a message like 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>

So then I did git pull my_branch_name

and it came back with this:

fatal: 'develop' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

but I had done git checkout my_branch right before that.

Could someone please let me know what I did wrong and how I can simply get the latest files that had been checked in?

Thanks!

GeekedOut
  • 16,905
  • 37
  • 107
  • 185

6 Answers6

71

I think you missed the name of the remote when pulling:

git pull <remote> my_branch_name

Run this command:

git remote -v

And check what is the name of the remote you want to pull from

EDIT:

If you are new to Git, I would recommend you this book. It covers from basic to advanced topics, is easy to understand and to read

davids
  • 6,259
  • 3
  • 29
  • 50
  • 1
    the remote -v command showed me the urls for the repostory. Then I ran the first command and got an error that I have to check in my latest code or it will be over-written. Then I tried to check in my latest code, and I got this error: error: failed to push some refs to 'https://branch_path' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. – GeekedOut Aug 21 '12 at 12:01
  • I really encourage you to read the book I pointed out in my answer. Is not very large and you'll become a git master :) – davids Aug 21 '12 at 12:08
  • BTW have you tried to push to your remote repository before pulling? – davids Aug 21 '12 at 12:09
  • What I ended up doing is a commit of my code, and then a pull of the remote branch. The weird thing was that it started doing a merge - was that what was supposed to happen? :) – GeekedOut Aug 21 '12 at 12:12
  • What was happening is that you had uncommitted changes, so you couldn't pull from the repository. Then you tried to push your changes, but there were some new commits in the remote repository you hadn't in your local one (that's the reason of the fast-forwards message). And finally, yes, whenever you pull from a repository, git fetches the new data and try to merge it if it is able to. So, `git pull` = `git fetch` + `git merge`. And again, I recommend you checking out that book, you won't regret it :) – davids Aug 21 '12 at 12:17
  • I have the same problem as GeekedOut. It is bazar with git that you can checkout a repo, make edits, checkin with no issues, but when you come to pull, you get the above error. git remote -v returns two lines: 1) origin myurl (fetch), 2) origin myurl (push). Is this correct, or is one needed for pull too? – John Little May 27 '13 at 11:44
  • 1
    This is not a helpful answer. `git remote -v` just lists "origin . What does someone do with that? – Cerin Jul 19 '17 at 00:10
  • True, but a reference to a book actually helped a lot. Legitimate source – Radzik Aug 04 '22 at 09:18
47

As the first error message indicated, you need to tell git where to look when it pulls for that branch:

In Git 1.8 and up, ensure you've checked out develop and run:

git branch --set-upstream-to origin/develop

or the shorter:-

git branch -u origin/develop

In Git prior to version 1.8:

git branch --set-upstream develop origin/develop

Once you've done that you can git pull without having to specify the remote or the branch.

If the remote origin is not yet set up, first run:

git remote add origin url

bcmcfc
  • 25,966
  • 29
  • 109
  • 181
  • 1
    thanks! In the set upstream command, where do I place the url or the repository? – GeekedOut Aug 21 '12 at 12:02
  • 2
    The URL is set in the configuration of the remote, rather than the branch's upstream configuration. – bcmcfc Aug 21 '12 at 13:00
  • 1
    How do you know if the origin is setup or not? When I do git remote -v it returns two lines, one for (fecth) and one for (push). Is a third line needed for pull? If so How does one add it? – John Little May 27 '13 at 11:46
  • 2
    Git status already says Im on master, which is the correct branch. In the git branch --set-upstream master origin/branch i ahve no idea what "master" and "origin" format should be. Should they be names, urls, ip addresses or the literal word "master" and "origin". I have read copious pages of documentation, and this key part still eludes. – John Little May 27 '13 at 11:49
  • [Pull](http://stackoverflow.com/q/292357/149998) is a `fetch` and `merge`, so will use `fetch`. Origin is the name given to the remote repo, it can technically be anything (Origin, BitBucket, GitHub, Dave) depending on what you've set up. Master is the name of the branch, which again can be anything. – bcmcfc May 28 '13 at 07:37
  • 1
    git 1.8.5 warns me: "The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to" – harschware Sep 09 '14 at 22:16
  • 2
    @harschware thanks for bringing it up, have updated the answer to support the changes within Git. – bcmcfc Sep 10 '14 at 07:37
46

try this command:

git pull origin master
git push -u origin master
navins
  • 3,429
  • 2
  • 28
  • 29
  • Hey this fixed my problem, but do you think you could explain what exactly this is doing? Thanks! – jj172 Apr 08 '15 at 23:50
  • 3
    The first cmd pull remote to local master branch, the second push to remote. `-u` means add upstream (tracking) reference, which solve the problem. – navins Apr 14 '15 at 07:01
5

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

Akash Kandpal
  • 3,126
  • 28
  • 25
2

What I like to do is...

$ git checkout master
$ git pull
$ git checkout <remotebranch>
$ git rebase master
Undo
  • 25,519
  • 37
  • 106
  • 129
0

The thing is that your local develop branch does not track the remote develop branch. "Tracking" means that your local branch has a direct relationship to a remote branch.

When your local branch is tracking corresponding remote branch, the "git pull" command would do what you expect it to do, that is pull the latest changes and merge them with local develop.

The easiest way to fix your problem is:

  1. Remove local develop branch
  2. In your Terminal or whatever thing you use just run a following command: git checkout --track origin/develop

Be aware of that you may have a different shortname of your remote repository and 'origin' could not work. In such case just run git remote -v and you will see the shortname you need on the left to a remote repo address.

If you wish to dig deeper, I strongly recommend you to read this part of a book https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches (Tracking Branches chapter) that https://stackoverflow.com/users/978515/davids recommended.

Radzik
  • 244
  • 2
  • 16