I'm trying to upload a navbar file to git, but it keeps saying that some references couldn't be pushed, and I don't know where I'm going wrong.
PS E:\navbar> git init
Initialized empty Git repository in E:/navbar/.git/
PS E:\navbar> git add README.md
fatal: pathspec 'README.md' did not match any files
PS E:\navbar> git commit -m "first commit"
Author identity unknown
*** Please tell me who you are.
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got '신은영@DESKTOP-0T69V65.(no
PS E:\navbar> git remote add origin https://github.com/kimdohyeon0811/learnit
PS E:\navbar> git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/kimdohyeon0811/learnit'
PS E:\navbar> git remote -v
origin https://github.com/kimdohyeon0811/learn_css.git (fetch)
origin https://github.com/kimdohyeon0811/learn_css.git (push)
PS E:\navbar> git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/kimdohyeon0811/learn_css.git'
PS E:\navbar>
CodePudding user response:
You have two separate problems here, and they're related. The first is that you've failed to configure your the name and email used in your commits, and so Git is refusing to commit any changes. The second is that because you have no commits in your repository, trying to push the branch main
or master
doesn't work, because it doesn't exist. That's the message that you're getting when you see “src refspec…does not match any.”
You need to configure your name and email, which are stored in user.name
and user.email
. Note that user.name
is a personal name, not a username. So, for example, someone might run these commands:
$ git config --global user.name "Pat Doe"
$ git config --global user.email [email protected]
Then, once you've made those changes, you can commit and it should succeed. Once you have commits, you can push them.
Note that if you want to use main
as the default branch but your repository is using master
, you can run git branch -m main
and that will rename the branch. If you want to do that, do it before you push.