一些记录
上传本地项目到已有远程仓库
git——上传本地项目到已有的远程仓库 - poowicat - 博客园
修改 pull 的默认配置为 rebase
git pull = git fetch + git merge
执行 git pull 命令时,默认是用 git merge 来合并代码的。大家都知道,用 merge 合并代码的节点不在一个分支上,不方便查看节点信息,所以很多公司是采用 git rebase 来合并代码的。针对这种情况,可以在自己的电脑终端,修改 git 的全局配置,将 pull 的默认配置改为 rebase。
全局修改 pull 的命令:
git config --global --add pull.rebase true
查看是否修改成功命令:
git config --global -l
问题记录
1.您有偏离的分支,需要指定如何调和它们。
zhq@B-12B5Q6LT-2022 comment % git pull origin master
来自 https://code.alipay.com/zhuhongquan.zhq/comment
* branch master -> FETCH_HEAD
提示:您有偏离的分支,需要指定如何调和它们。您可以在执行下一次pull 操作之前执行下面一条命令来抑制本消息:
提示: git config pull.rebase false # 合并
提示: git config pull.rebase true # 变基
提示: git config pull.ff only # 仅快进
提示:
提示:您可以将 "git config" 替换为 "git config --global" 以便为所有仓库设置
提示:缺省的配置项。您也可以在每次执行 pull 命令时添加 --rebase、--no-rebase,
提示:或者 --ff-only 参数覆盖缺省设置。
fatal: 需要指定如何调和偏离的分支。
解决方法:git pull origin master --rebase。即通过变基将两个不相关的分支合并。
2.当 git pull 碰到拒绝合并无关历史
问题描述:在github上建了个仓库,里面只有一个 README.md
文件。然后想把本地的一个项目传上去,然后就碰到了这样一个问题!当把本地仓库和远程仓库关联后准备提交代码时,git 提示我请先使用 git pull
:
但当我 git pull origin master
时就出现了这样一条错误:
解决方法:
git pull origin master --allow-unrelated-histories