others-how to push a local repository to a github new repostory?
1. Purpose
In this post, I will demonstrate how to push a local git repository to github. I will create a new local repository and then push it to a new github repository.
2. The procedure
Before doing the job, let’s review the environments that we have: 1) We have created a repository in github, named kotlin-hello2 2) We have created a local git repository locally named kotlin-hello2
Here is the steps to do the job:
1) Add remote repository as my local git repository’s remote peer.
➜ kotlin-hello2 git:(master) ✗ git remote add origin https://github.com/bswen/kotlin-hello2.git
2) Push local repo’s master branch to github remote repository
➜ kotlin-hello2 git:(master) ✗ git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/bswen/kotlin-hello2.git'
➜ kotlin-hello2 git:(master) ✗ git push -f origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/bswen/kotlin-hello2.git'
➜ kotlin-hello2 git:(master) ✗ git push -f origin master --verbose
Pushing to https://github.com/bswen/kotlin-hello2.git
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/bswen/kotlin-hello2.git'
What does error: src refspec master does not match any
mean?
It means that there is no matching branch in your remote branch, because the default branch in github is the main
branch, not the master
branch, so if you push master
to main
, there will be an error.
solution:
Create a branch named master
in your remote github repository, then do as follows:
➜ kotlin-hello2 git:(master) git remote -v
origin https://github.com/bswen/kotlin-hello2.git (fetch)
origin https://github.com/bswen/kotlin-hello2.git (push)
➜ kotlin-hello2 git:(master) git push origin master
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 8 threads
Compressing objects: 100% (14/14), done.
Writing objects: 100% (22/22), 59.75 KiB | 9.96 MiB/s, done.
Total 22 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote: https://github.com/bswen/kotlin-hello2/pull/new/master
remote:
To https://github.com/bswen/kotlin-hello2.git
* [new branch] master -> master
➜ kotlin-hello2 git:(master)
Now it works!
3. Summary
In this post, I demonstrated how to solve the error: src refspec master does not match any
error when trying to push a local repository to github remote repository, the key point is to match your local branch to the remote one. That’s it, thanks for your reading.