首先git init在本地生成.git文件
接着git add . 将所有文件添加到仓库
再git commit -m "注释"
接着git remote add origin "此处是你github中仓库地址"
最后输入
git push -u origin master
如果新建的仓库是空的,则要加上**-u** ,等远程仓库有内容时,下次再加入只需要:
git push origin master
由于我添加了三个工程项目到同一仓库中,故添加第一个项目时按照此方法成功了,在git第二个项目时,执行到最后一步出现报错
error: failed to push some refs to 'git@github.com:zuiwangzuo/myDemoPro.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.
解决方法:出现此问题的原因是github中刚上传的第一个项目不在第二个项目中,所以只需先将远程仓库中代码pull到本地再执行push操作即可。
git pull --rebase origin master
再次push
git push origin master