-
一、将本地代码推送到远程仓库上
- 选择一个目录作为git仓库,比如我选择的是E盘目录下:
cd e:
- 创建一个目录作为仓库,比如我创建一个“gitPush”:
mkdir gitPush

- 进入gitPush目录:
cd gitPush

- 初始化仓库
git init

- 关联远程库
$ git remote add origin https://github.com/Sangrita/EXtestWeb.git

将链接改成你的远程仓库的链接。默认的远程库 的名字为“origin”。
- 将本地库的所有东西添加到远程仓库里:
git add .
git commit -m "完成了发布作业和做作业页面的主要内容,但是代码还没整理"
git push -u origin master
在push代码的时候回让你输入你的github的用户名和密码

-
二、常见错误提示
- 第一次push时,出现以下错误:
error: 无法推送一些引用到 'https://github.com/YangTangEXtest/web.git'
提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外
提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更
提示:(如 'git pull ...')。
提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。

解决办法:
出现这种错误,通常都是因为你的远程仓库包含你本地尚不存在的提交,比如:ReadMe.txt。这时我们只需要把远程仓库里的提交clone下来,把要添加的东西加入进去再push就行了。
$ git clone https://github.com/YangTangEXtest/web.git

- push时出现错误:
error: 无法推送一些引用到 'https://github.com/YangTangEXtest/web.git'
提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外
提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更
提示:(如 'git pull ...')。
提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。
解决办法:
出现这个错误,通常是因为你本地哟多次提交,你需要把他们合并之后再push。
git push -u origin +master

-
常用命令
- git remote -v
网友评论