git本地仓库关联github仓库

准备工作。

在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.

根据说明我们也可以看到是因为本地仓库落后与服务器仓库

================================================================

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值