0

My branch in the Github repository is "master". In the terminal I did:

git branch

and the output is:

* main

my-temporary-work

I wanted to push a file to Github and I used:

git add exploratory_analysis.ipynb

git commit -m "New version"

git push origin master

The "git add" and "git commit" commands work. However, the last command (i.e., "git push origin master") does not work, and I get this error:

error: src refspec master does not match any

error: failed to push some refs to '[email protected]:NAME-OF-USER/REPOSITORY-NAME.git'

That is, it looks like I cannot push any code from my laptop to Github. How can I fix it?

1
  • You literally cannot push files to another Git repository. You can only push commits. Commits contain files, but you either get the whole commit sent, or nothing sent. Your conversation with Davis S is on the right track, but you'll need to make sure you have all the commits that the upstream (GitHub) repository has, before you try to add a commit on to their commits. Commented Dec 17, 2020 at 6:02

2 Answers 2

3

I faced the same issue some days ago. If you created a new repository nowadays(2020) then the default branch in main on GitHub.

you can check on GitHub now in your repository branches.

so that's why you need to run

git push origin main

instead of

git push origin master

Goodluck with more details you can watch video

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. I deleted a few files from my laptop which were not pushed yet, and then "git push origin main" worked on a single file.
I am having a similar problem but mine is main branch and i tried what he did by saying to push to master but I can't get it resolved
your suggestion did not work for me, instead i used git push origin main -f
0

Why are you pushing to master if the branch commands outputs main? Try 'git push origin main'

Also found this explanation for the change: https://stackoverflow.com/a/65008828/1959534

5 Comments

Hello, I also tried to use 'git push origin main'. However, if I use 'git push origin main', then all files in the folder are pushed from my laptop into Github. When I did 'git push origin main', then approximately 4000 files were pushed into Github, and it took quite a long time. My goal is to push one single file at a time (e.g., push only exploratory_analysis.ipynb).
You sure there isn't anything else that is staged (check with git status)? If you only did git add on exploratory_analysis.ipynb and committed it then that is that will be pushed.
Hi David S, I just did "git status" now. This is the result of "git status": On branch main Your branch is ahead of 'origin/main' by 19 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean
Akey, that explains why there are more files that are pushed, there are an additional 18 commits that are pending locally. Should they be pushed also? If not you can unstage all of them with 'git reset HEAD~19' and then re-stage your one file that you want to push.
I did that but it does not work. I did 'git reset HEAD~19' but then I still get the same error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.