I am making my first commit using GIT in VS Code. I only have one main branch in Github and while I was using git push, I send it as:
git push origin/master accidentally.
Error:
error: src refspec main does not match any
error: failed to push some refs to ‘https://github.com/"repoName".git’
I tried git reset origin/main it shows me this message:
Unstaged changes after reset:
M README.md
D a.jpg
And when I tried again with git push origin main, it still throws the same error
I want to push it in my repo in main branch(there is no master branch in mine)
2
Answers
Because on remote server you make changes and this changes should pull first before pushing it
First stash changes that makes in the files:
Second pull changes from remote branch
Push again
And push changes in the local repository that you make before pull with stash command
Notice
If you push commits to remote server and edit some commit in the local repository that pushed to remote server, you should rewrite on remote repository and you problem will solve in one command:
I’m pretty sure you did
git push origin master
, not ‘origin/master’git push origin master
– even though it didn’t work – should not have changed any of your configuration so you should be able to push as if you never made the mistake. In other words, you do not have to fix anything because ofgit push origin master
.The problem is what you have done after 🙂
git reset
made the tip of your local branch match the tip of the remote branch and the local commits have been ‘unwound’ from your local branch. The changes you made locally are now seen by git as not committed.I think the easiest solution for this specific situation (new repo, just 2 files) is:
git add --all
– This:a.jpg
to the list of changes to commitgit commit -m 'Deleting a.jpg and updates to the README'
git push --set-upstream origin main
:origin main
i.e. from now on it’s onlygit push
.