初次提交
- 在要提交的项目处右键,有
Git Bash Here
,点击后出现类似cmd命令行,也可以在任意处或开始菜单中打开Git Bash Here
,然后输入cd c:/XXX/XXX
,即要提交的项目路径 - 初始化
$ git init
Initialized empty Git repository in E:/myProject/XX/.git/
- 连接远程库
$ git remote add c6 git@gitee.com:XXX/XX.git
c6
是本地的自定义名称,是git@gitee.com:XXX/XX.git
的别名,可自由选择,例如origin
git@gitee.com:XXX/XX.git
是远端项目的ssh,以码云为例:
输入命令后可以用以下命令进行查看
$ git remote -v
c6 git@gitee.com:XXX/XX.git (fetch)
c6 git@gitee.com:XXX/XX.git (push)
若要删除
$ git remote rm c6
- 提交(push)
$ git commit -m "c6"
c6
是一个备注信息,写本次提交的内容介绍等
$ git add .
将文件夹下的所有内容作为要提交的内容
$ git push c6 master
此处的c6
是第三步连接远程库时所取的名字
如果远端项目有文件,会提示错误
$ git push c6 master
To gitee.com:XXX/XX.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@gitee.com:XXX/XX.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.
错误的意思是说
![拒绝]master->master(先取)
错误:未能将一些参考资料推送到“git@gitee.com:XXX/ XXX .git”
提示:更新被拒绝,因为远程包含您所做的工作
提示:没有本地。这通常是由另一个存储库推送引起的
提示:指向相同的ref。您可能想首先集成远程更改
提示:(例如,“git pull…”)然后再推。
提示:详情请参阅“git push -help”中的“关于快进的说明”。
所以需要先更新项目,获取远端的项目内容
$ git pull --rebase c6 master
然后执行提交
$ git push c6 master
至此,远端将有了刚提交的内容
提交到另一个代码托管库
完成以上步骤后,若想将代码提交到Github上
- 连接远端,即重复上面的第三步
$ git remote add github git@github.com:XXX/XX.git
- 提交代码,即重复上面的第四步
$ git push github master
提交更改
$ git commit -m "提交的内容介绍"
$ git push c6 master