-1

I'm trying to upload a new project to Github. I created the repository and git bashed on the repository folder. But when I use these two commands I get the following errors:

git commit -m "first commit"
On branch master
Initial commit    
nothing to commit (create/copy files and use "git add" to track)

git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'repolink.git'

I tried that command: git push --set-upstream origin main

I got the same error:

error: src refspec main does not match any
error: failed to push some refs to 'repolink.git'

How can I fix this problem? What am I doing wrong? Thanks in advance...

-----UPDATE-----

I tried the answer in the following question: Nothing to commit - Git

And it worked! Thank you all...

zeynep
  • 15
  • 5
  • 1
    Did you add the files you want to commit before committing? – dan1st Mar 03 '21 at 16:14
  • Yes, I did. I was checking other questions related to that problem and I saw that command: git status -s --ignored I have a .gitignore file. Can that be the root of my problem? – zeynep Mar 03 '21 at 16:18
  • The .gitignore contains a vlacklist with files that can't be added. If you cannot add anything, you cannot commit. – dan1st Mar 03 '21 at 16:23

2 Answers2

1

Two things I can see here.

  1. It seems that you try to commit without any files. So you probably need to use git add before to add at least one new file or call git commit -am which automatically adds all modified tracked files.
  2. Your status shows "On branch master". With this I guess you also need to do git push -u origin master. The master to main renaming was recently introduced by GitHub, so not sure if they automatically consider this.
FreshD
  • 2,914
  • 2
  • 23
  • 34
  • 1. On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) 2. error: src refspec main does not match any error: failed to push some refs to 'repolink.git' I tried them, it didn't work. – zeynep Mar 03 '21 at 16:27
  • What do you get when you do a `git status`? The second error might be caused as a consequence of the first as you cannot push when there are not commits to push. – FreshD Mar 03 '21 at 16:29
  • On branch main No commits yet nothing to commit (create/copy files and use "git add" to track) I got this. – zeynep Mar 03 '21 at 16:32
  • This means that you currently don't have any files in the repositroy. Maybe you start with a `touch README.md` and add this with `git add README.md`. Then you should be able to commit and push. – FreshD Mar 03 '21 at 16:34
1

Seems like you are trying to push to main but your local git is under branch master. I would check my local repository status and tool versions.

Try git status to understand what is happening in your local, and git remote -v to determine where and what happens in remote.