Git上传远程仓库操作流程
1、创建仓库
2、切换路径到你的项目
3、克隆远程仓库
git clone <版本库的网址> <本地目录名>
如果报错关掉git bash,或者将https改成http
4、创建项目
5、打开终端输入命令(也可以选择可视化)
1)添加所有要提交的文件
git add .
2)commit,本次提交说明
git commit -m '提交说明'
3)关联(添加)GitHub远程仓库
git remote add origin 仓库地址
tip: origin 远程主机名,master 主分支
- 删除远程主机
git remote rm origin
- 查看所有远程主机
git remote
4)拉去远程仓库最新代码
git pull origin master
5)推送本次提交到仓库
git push origin master
6)返回gitee刷新,发现上传成功
tip: 加了参数-u后,以后即可直接用git push 代替git push origin master
git push -u origin master
tip: 可是当你第一次push的时候一般会遇到如下报错:
$ git push origin master
To https://github.com/yuanchao614/wecoder.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/yuanchao614/wecoder.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
这种错误的主要原因是你的远程仓库的内容有改动但是你本地并没有拉去最新的代码所以会报错。
解决方法:
首先:
git pull origin master --allow-unrelated-histories
可能会出现vim编辑不用管直接保存退出就行
然后建议做完上一步之后再重新:
git add .
git commit -m '提交说明'
git push origin master