记录:不同的两个git仓库如何进行代码合并

Jiafeng

分类: github 0 0

一、前言

最近因为项目需要,在甲方驻场开发,而公司内部也需要部署一套,于是就产生了两个git仓库,而代码又需要经常同步...

二、操作步骤:(这里用gitee和github,把gitee代码合并到github并提交)

  1. ## 初始化git
  2. $ git init
  3. ## 添加不同的远程仓库地址
  4. $ git remote add gitee 'https://gitee.com/****.git' ## gitee 远程仓库名称默认,可以自定义
  5. $ git remote add github 'https://github.com/****.git' ## github 远程仓库名称默认,可以自定义
  6. $ git remote -v ## 添加完成,查看当前连接的远程地址
  7. ## 本地创建不同分支,并关联远程分支
  8. $ git fetch gitee master ## 拉取远程分支到本地(gitee是刚才上面我们给远程仓库起的名称,dev是要拉取的分支)
  9. $ git switch -c dev gitee/master ## 在本地创建dev分支,并切换到该分支
  10. $ git fetch github master ## 拉取远程分支到本地(gitee是刚才上面我们给远程仓库起的名称,dev是要拉取的分支)
  11. $ git switch -c master github/master ## 在本地创建master分支,并切换到该分支
  12. ## 合并提交
  13. $ git merge --no-ff dev --allow-unrelated-histories ## --allow-unrelated-histories(允许合并两个完全不相关的分支)
  14. $ git push github

三、一些常用的指令

  • 创建+切换分支:git checkout -b 或者git switch -c
  • 删除分支:git branch -d
  • 回退上一个版本:git reset --hard HEAD^
  • 记录用户名密码:git config credential.helper store
  • 禁止快进式合并: git merge --no-ff
  • 清除git缓存

    1. git rm -r --cached .
    2. git add .
    3. git commit -m 'update .gitignore'

fatal: Authentication failed for 又不弹出用户名和密码

输入命令:git config --system --unset credential.helper,不行可以把C盘用户下的 .gitconfig 先移出

如果commit注释写错了,需要改一下注释:git commit --amend,这时候会进入vim编辑器,修改完成你要的注释后保存即可。

  • 1人 Love
  • 0人 Haha
  • 0人 Wow
  • 0人 Sad
  • 0人 Angry
github

作者简介: Jiafeng

共 0 条评论关于 “记录:不同的两个git仓库如何进行代码合并”

发表评论

昵称、邮箱为必填项,电子邮件地址不会被公开