Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull remote branch cannot find remote ref

Tags:

git

I'm not sure why this doesn't work. When I do git branch -a, this is what I see:

enter image description here

I'm trying to pull from the DownloadManager on the online GitHub repository. I have tried

  • git pull, but then it complains about not knowing which branch to pull from
  • git pull origin, doesn't know which branch
  • git pull origin downloadmanager fatal: Couldn't find remote ref downloadmanager. Unexpected end of commands stream
  • git pull origin remotes/origin/DownloadManager 'fatal couldn't find remote ref remotes/origin/DownloadManager. Unexpected end of commands stream

Is there something I'm missing? In Xcode, When I try to connect to the repository, nothing ever shows up. I have been able to push to it in the past. But I can't push again until I pull the most recent changes.

like image 795
Crystal Avatar asked Jul 19 '12 00:07

Crystal


People also ask

Does git pull connect to remote?

Fetching and pulling from Git remotesBoth git fetch , and git pull can be used to read from a remote repository. Both commands have different operations that are explained in further depth on their respective links.

How do I pull from a specific branch remote?

If you have a single remote repository, then you can omit all arguments. just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.

How do I see remote branches in git?

To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands. If you approve the changes a remote branch contains, you can merge it into a local branch with a normal git merge .


2 Answers

Be careful - you have case mixing between local and remote branch!

Suppose you are in local branch downloadmanager now (git checkout downloadmanager)

You have next options:

  1. Specify remote branch in pull/push commands every time (case sensitive):

    git pull origin DownloadManager

    or

    git pull origin downloadmanager:DownloadManager


  1. Specify tracking branch on next push:

    git push -u origin DownloadManager

    (-u is a short form of --set-upstream)

    this will persist downloadmanager:DownloadManager link in config automatically (same result, as the next step).


  1. Set in git config default remote tracking branch:

    git branch -u downloadmanager origin/DownloadManager

    (note, since git 1.8 for branch command -u is a short form of --set-upstream-to, which is a bit different from deprecated --set-upstream)

    or edit config manually (I prefer this way):

    git config --local -e

    -> This will open editor. Add block below (guess, after "master" block):

    [branch "downloadmanager"]         remote = origin         merge = refs/heads/DownloadManager 

and after any of those steps you can use easily:

git pull

If you use TortoiseGit: RightClick on repo -> TortoiseGit -> Settings -> Git -> Edit local .git/config

like image 195
radistao Avatar answered Sep 20 '22 15:09

radistao


This error happens because of local repository can't identify the remote branch at first time. So you need to do it first. It can be done using following commands:

git remote add origin 'url_of_your_github_project'  git push -u origin master 
like image 25
UWU_SANDUN Avatar answered Sep 18 '22 15:09

UWU_SANDUN