0

Can someone tell me how to solve this: When I execute git init I only see (master) not (master->origin) and, when I do git branch, it returns nothing and when I try to push I get this error:

git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'github.com:BghAek/something.git'
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 1
    When you say "existing project", do you mean that this code has never been committed to a git repo before? – Code-Apprentice Sep 23 '21 at 03:42
  • https://stackoverflow.com/a/7572252/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+error%3A+src+refspec+master+does+not+match+any – phd Sep 23 '21 at 05:30

2 Answers2

2

After git init, you need to commit the code with git add . and then git commit -m "Initial commit". Then you will be able to git push if your repository has a remote that points to GitHub or some other online service.

I strongly encourage you to learn the basics of git. Pro Git is a good place to start. The first three chapters explains the fundamental concepts that you will use regularly. The remaining chapters get into more advanced concepts if you need them later.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • 1
    You won the race this time! – matt Sep 23 '21 at 03:44
  • thanks for your respect.... now I do all what you say but when I write git push origin master or git push -u origin master it tell me error: the requested upstream branch 'origin' does not exist . what i do ? – Amro Elkeran Sep 23 '21 at 04:02
  • @عمروالقيران The next step is to add your GitHub repo as a remote. You can do this with the `git remote` command. You can do `git help remote` to get more info about it. – Code-Apprentice Sep 23 '21 at 18:59
1

In order to push from your new local repository, you need to:

  • make sure you have an empty newly created GitHub repository
  • rename your local branch from master to main (check your Git version): git branch -m master main
  • execute git config --global init.defaultbranch main to use main from now on for any new local repository (since GitHub is also using main by default)
  • add the remote GitHub repository URL as remote origin:
    git remote add origin https://github.com/<me>/<myNewRepo>
  • finally push: git push -u origin main
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250