error: src refspec master does not match any. 错误

添加远程仓库出现如下问题:

error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/liyihang/CorePython.git'

出现这个问题是因为本地仓库为空,我们只要在本地仓库中tianji

添加相关的文件即可。然后执行

git add -A

接着提交,

H:\Python_demo\CorePythonApplicationProgramming>git commit -m "chapter1"
[master (root-commit) 4c820d9] chapter1
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 chapter1/a.txt

之后执行,

git push -u origin master

执行后出现如下错误;

H:\Python_demo\CorePythonApplicationProgramming>git push -u origin master
To github.com:liyihang/CorePython.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:liyihang/CorePython.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

上面提示我们需要执行

git pull

我们只需要执行

H:\Python_demo\CorePythonApplicationProgramming>git pull --rebase origin master
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
warning: no common commits
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:liyihang/CorePython
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: chapter1

最后执行下面git push命令即可;

H:\Python_demo\CorePythonApplicationProgramming>git push -u origin master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 319 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
Branch master set up to track remote branch master from origin.
To github.com:liyihang/CorePython.git
   1cd7481..c6ba515  master -> master

最后即可以添加远程仓库。

点赞