0
votes

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?

2
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. - torek

2 Answers

3
votes

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

0
votes

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