准备工作。
在github上创建仓库springboot,并添加README文件。
在本地创建仓库demo,并初始化成一个springboot项目。
现在要做的工作是将本地仓库中的内容推送到github。
1.git remote add origin git@github.com:TianShiHeiDe/springboot.git
在本地git配置文件中添加一个远程仓库,并命名为origin。
================下面是一些解释=======================
其中origin是一个别名,其代表了后面的URL地址。
这条命令会将这个地址写入git的配置文件中。如下:
如此我们就可以使用这个别名指向的URL地址。方便以后的操作。
如果你想查看现在所有的仓库地址,可以使用
git remote -v
================END==================
2.git pull --allow--unrelated-histories origin master
首先我们需要从github上拉取README文件拉取到本地。因为这是两个毫无关系的项目,所以需要使用--allow--unrelated-histories参数,
后接需要推送的地址以及分支。
======================================
如果不使用此参数会出现如下错误:
$ git pull origin master
From github.com:TianShiHeiDe/springboot
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
=======================================
3.git push -u origin master
将本地文件推送的到github上。
=================================================================
如果没有2步骤的铺垫,是无法推送成功的。
会出现如下问题:
$ git push -u origin master
To github.com:TianShiHeiDe/springboot.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:TianShiHeiDe/springboot.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.
根据说明我们也可以看到是因为本地仓库落后与服务器仓库
================================================================