在本地的learngit
仓库下运行命令:
$ git remote add origin git@github.com:michaelliao/learngit.git 关联远程仓库
$ git remote add origin https://github.com/JackLiu16/ansible
$ git remote add origin https://github.com/JackLiu16/ansible第二次执行这个命令会出现错误
fatal: remote origin already exists.
$ git remote remove origin https://github.com/JackLiu16/ansible
usage: git remote remove <name>
$ git remote remove origin 只需要origin这个名字就可以了,不用后面的网址。origin这个名字是和该网址库相关联的别名,
可以自己任意定义
请千万注意,把上面的michaelliao
替换成你自己的GitHub账户名,否则,你在本地关联的就是我的远程库,关联没有问题,但是你以后推送是推不上去的,因为你的SSH Key公钥不在我的账户列表中。
添加后,远程库的名字就是origin
,这是Git默认的叫法,也可以改成别的,但是origin
这个名字一看就知道是远程库。也可以关联多个远程仓库。名字也可以任意自定义。
下一步,就可以把本地库的所有内容推送到远程库上:
$ git push -u origin master
$ git push -u origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 289 bytes | 289.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/JackLiu16/ansible
831c8e3..4e8ef8a master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
报错:
$ git push origin
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
$ git push --set-upstream origin master
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/JackLiu16/ansible'
$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/JackLiu16/ansible'
原因:
本地仓库为空
解决方法:使用如下命令 添加文件;
$ git add add.php addok.php conn.php del.php edit.php editok.php ftpsql.sql index.php
$ git commit -m "init files"
参考:https://www.cnblogs.com/jeremylee/p/5715289.html
https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013752340242354807e192f02a44359908df8a5643103a000
https://blog.csdn.net/dengjianqiang2011/article/details/9260435
https://www.jianshu.com/p/dcbb8baa6e36