git简单配置、报错-refusing to merge unrelated histories的处理方法

本文详细介绍Git的下载、基本用法及配置,包括创建和推送仓库的步骤,并提供了解决refusing to merge unrelated histories及push错误的方法。

git 下载

Git官方网站 ,选择适合自己电脑系统的git下载

git 基本用法

安装好git后就可以操作了,在桌面右击或者开始菜单中找到git bash启动命令窗口。

Git 全局设置:

git config --global user.name "ASxx" 
git config --global user.email "123456789@qq.com"
 
创建 git 仓库:
 
mkdir wap // 项目在本地的路径
cd wap
git init 
touch README.md 
git add README.md 
git commit -m "first commit" 
git remote add origin https://git.oschina.net/name/package.git  // 远程仓库地址
git push -u origin master
 
 
已有项目:
 
cd existing_git_repo
git remote add origin https://git.oschina.net/name/package.git
git push -u origin master

常见 error

笔者在使用git过程出现了-refusing to merge unrelated histories错误,经过一番摸索发现主要原因是本地仓库和远程仓库实际上是独立的两个仓库

解决方法
在pull命令后紧接着使用–allow-unrelated-history选项来解决问题(该选项可以合并两个独立启动仓库的历史)。命令使用:

 git pull origin master --allow-unrelated-histories

紧接着将本地仓库的提交推送到远程github仓库上就可以了,命令使用:

git push <远程主机名> <本地分支名>:<远程分支名>

出现git push报错error: failed to push some refs to 'git@github.com:原因是GitHub远程仓库中的README.md文件不在本地仓库中。
解决方案:

 git push -u origin master
To git@github.com:xxx/xxx.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:xxx/xxx.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.

解决方案

git pull --rebase origin master
git push -u origin master

参考来源

[1] https://git-scm.com/docs
[2] https://blog.csdn.net/u012145252/article/details/80628451

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值