git pull remote branch cannot find remote ref
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
If the remote branch was deleted (or renamed), then you might get such error when trying to fetch that old-branch:
$ git fetch --prune --all
Fetching origin
fatal: couldn't find remote ref refs/heads/old-branch
error: Could not fetch origin
Check your local git config if it still refers to the old-branch:
$ git config --get-all remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
+refs/heads/old-branch:refs/remotes/origin/old-branch
+refs/heads/master:refs/remotes/origin/master
Removing the old refs entries, can fix the fetch problem:
$ git config --unset-all remote.origin.fetch
$ git fetch --prune --all
Fetching origin
...
* branch HEAD -> FETCH_HEAD
If none of these answers work, I would start by looking in your .git/config
file for references to the branch that makes problems, and removing them.
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:
Specify remote branch in pull/push commands every time (case sensitive):
git pull origin DownloadManager
or
git pull origin downloadmanager:DownloadManager
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).
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