skip to Main Content

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


  1. Because on remote server you make changes and this changes should pull first before pushing it

    First stash changes that makes in the files:

    git stash
    

    Second pull changes from remote branch

    git pull origin master
    

    Push again

    git push origin master
    

    And push changes in the local repository that you make before pull with stash command

    git stash pop
    

    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:

    git push --force origin master
    
    Login or Signup to reply.
  2. I send it as: git push origin/master accidentally.

    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 of git 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:

    1. git add --all – This:
      1. adds the deletion of a.jpg to the list of changes to commit
      2. adds the changes in README.md to the list of changes to commit
    2. git commit -m 'Deleting a.jpg and updates to the README'
    3. git push --set-upstream origin main:
      1. This pushes the changes to the origin repo.
      2. From now on you don’t need to specify origin main i.e. from now on it’s only git push.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search