1. 检查本地是否安装了git
git version
git version 2.10.0
创建一个远程仓库在git上面repository github会生成一个url连接
2.
$git init
Initialized empty Git repository in /Work/project/.git/
$git add .
$git commit -m '本地连接我的github'
[master (root-commit) 47ec6ff] 本地连接我的github
1 file changed, 2 insertions(+)
create mode 100644 init/initday170702.php
$git remote add origin https://github.com/sql1314/sql1314for20170702.git ####在本地仓库添加一个远程仓库,并将本地的master分支跟踪到远程分支
$git pull origin master
fatal: refusing to merge unrelated histories
解决方案
我在Github新建一个仓库,写了License,然后把本地一个写了很久仓库上传。因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码,在git pull
,这句代码是在git 2.9.2版本发生的,最新的版本需要添加--allow-unrelated-histories
$git pull origin master --allow-unrelated-histories
From https://github.com/sql1314/sql1314for20170702
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 README.md
$git push origin master
okay 好了