0

I'm trying to get a branch from a git project and put it into another git repo however when I do this and trying to push I have this error

the source reference specifier refs/heads/master does not correspond to any reference error: impossible to push references to "origin"

Also I've noticed that the empty project has no branch even the master one.

grg
  • 5,023
  • 3
  • 34
  • 50
  • What is the command you use? What is the output of `git branch -a -v` in the source repo? – axiac Dec 30 '20 at 17:58
  • You are correct in stating that an empty repository (a repository with no commits) has no branches. Since Git is all about commits, when there are no commits, there is nothing to be about, and you cannot create any branch names. Since `git push` works by sending commits, usually as found by branch names, if you have no commits, there is no reason to run `git push`. (Well, there are some weird corner cases but for those you'd run `git fetch` first anyway.) – torek Dec 31 '20 at 00:33

1 Answers1

0

If you have cloned the first project, and want to push a branch to a second remote empty repository (no commits), you would do:

cd /path/to/cloned/first/project
git remote add second https://url/second/empty/repository
git switch <theCorrectBranch>
git push -u second <theCorrectBranch>:main

That would push <theCorrectBranch> to the branch main of the second remote empty repository.

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