0

Trying to add version control for webpage, have used git before for various projects, never encountered this error:

error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/aman-tugnawat/MangoDevelopersWebpage.git'

Looked a these answer for solution yet no progress, at these links.

https://stackoverflow.com/a/7543112/4382835

src refspec master does not match any when pushing commits in git

The possible reason I am thinking: enter image description here

Still trying to understand though what Github request's to skip the step of initializing the README.md.

Followed exactly in this sequecne:

git init
echo "# MangoDevelopersWebpage" >> README.md
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/aman-tugnawat/MangoDevelopersWebpage.git
git push origin master

Want an understanding of whats happening rather than the code.

Aman Tugnawat
  • 92
  • 1
  • 2
  • 12
  • 1
    What's the name of your local branch, `master`? – Mincong Huang May 02 '18 at 11:45
  • yeah, it's `master`, I solved the problem, but still need explaination. – Aman Tugnawat May 02 '18 at 11:56
  • what i did was remove the README.md, which I added after the git init. – Aman Tugnawat May 02 '18 at 11:57
  • Github suggests not to add README.me if you already have some existing files in your repo, i think the reason lies there, can anyone explain me the reason. – Aman Tugnawat May 02 '18 at 12:01
  • @MincongHuang could you please tell if I am going in the right direction. – Aman Tugnawat May 07 '18 at 15:48
  • I don't think README.md is the problem here. Without README.md in the initialization, GitHub creates an empty repository for you—but it doesn't block your from pushing a new branch. I think you might have done a `git push origin master` before commit as described in https://stackoverflow.com/questions/4181861/, but I'm not sure. – Mincong Huang May 07 '18 at 18:36

3 Answers3

3

had you checked if you have initialize correctly globals like user.email, user.name ? That's worked fine for me.

first you can check :

you@yourPC MINGW64 ~/your-file(master)
$ git config --list

if anything is wrong, so do as follows :

step 1:

you@yourPC MINGW64 ~/your-file(master)
$ git init
Reinitialized existing Git repository in C:yourPath/your-repo

step 2:

you@yourPC MINGW64 ~/your-file(master)
$ git add .

step 3:

you@yourPC MINGW64 ~/your-file(master)
$ git commit -m "second commit"

step 4:

you@yourPC MINGW64 ~/your-file(master)
$ git config --global user.name "Your Name"

step 5:

you@yourPC MINGW64 ~/your-file(master)
$  git config --global user.email you@example.com

step 6:

you@yourPC MINGW64 ~/your-file(master)
$  git push origin master
marcdahan
  • 2,654
  • 25
  • 25
0

Understood

Why Github suggests not to make README.md when creating push a already existing local repo to a new remote repo at GitHub?

As that would require a git pull to merge of the local and remote Repo, which might be hard for beginners to understand.

Solved the problem by removing by force removal of README.md

git rm README.md -f

then

git commit origin master

Read more about: git merge here https://git-scm.com/docs/git-merge

Aman Tugnawat
  • 92
  • 1
  • 2
  • 12
0

i had same error

when you first time connect to github or sth like that

you need to config

i solve it by git GUI

gitGUI want me to connect and problem resolved

  1. go to your project folder project forlder git GUI
  2. open Git GUI here
  3. from main bar in app choose remote add remote by git gui
  4. copy url from your new repository in github into this form copy git https url paste it in GIT GUI
  5. then stage changes
  6. then commit them
  7. then push
  8. then it open prompt for user pass
saber tabatabaee yazdi
  • 4,404
  • 3
  • 42
  • 58