0

I have a local repo that was initially cloned from a branch (using git clone --single-branch). That branch was merged into master and then deleted.

When I tried to switch to master in my local repo using git checkout master, I got error: pathspec 'master' did not match any file(s) known to git. I had to do a git checkout -b master instead, and then git status said I am on branch master.

But when I do a git pull, it is still pointing to the deleted branch because it prints out fatal: Couldn't find remote ref refs/heads/deleted-branch-name.

How do I remove any remaining references to the deleted branch, so that git pull pulls from the master branch?

aynber
  • 22,380
  • 8
  • 50
  • 63
pacoverflow
  • 3,726
  • 11
  • 41
  • 71
  • Did you make a *single-branch* clone (using `git clone --depth` or `git clone --single-branch`)? – torek Aug 26 '19 at 21:11
  • Yes I made a single-branch clone. – pacoverflow Aug 26 '19 at 21:18
  • That's the root of the problem, then. You'll need to either convert it back to a full clone (or replace it with a full clone) or change your single branch to be the branch `master`. – torek Aug 26 '19 at 21:19
  • Thanks, I converted it to a full clone using [this answer](https://stackoverflow.com/a/17714718/782011). – pacoverflow Aug 26 '19 at 22:11

1 Answers1

1

When you clone a single branch, you only get that single branch, not master. When you then execute git checkout -b master, you are checking out to a branch you are creating on the fly. That is, you create a local branch called master and you checkout to that branch. Of course, that master branch is not related to your remote master. You could have used git fetch origin to get all the branches of the repo. Example:

git fetch origin
git checkout -b master # creates a new branch called master
git merge origin/master # merge the master branch from the repo into yours
mfnx
  • 2,894
  • 1
  • 12
  • 28