原由
方法
步骤:
- 在内部代码托管平台新建空白仓库A
- git clone A 获取本地仓库
此时执行
cat .git/config
得到:本地分支[branch "master"] ,和指向远程仓库A [remote "origin"]
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[submodule]
active = .
[remote "origin"]
url = git@xxxxxxxx/cpython.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
- 将来源代码添加到另一个远程来源upstream
git remote add upstream https://github.com/user/repo
此时,
cat .git/config
获得:
[remote "upstream"]
url = https://github.com/python/cpython
fetch = +refs/heads/*:refs/remotes/upstream/*
- 从远程来源:upstream 拉取代码到本地分支
git pull upstream 【分支】
- push到内部远程来源origin
git push origin 【分支】
- tag迁移
拉取upstream的远程tag到本地
git fetch upstream
查看本地tag
git tag
推送本地tag到orgin远程
git push origin --tags
其他指令参考https://blog.csdn.net/qq_34273222/article/details/107080031
其他便捷方法
- GitLab在Settings => Repository => Mirroring Repository中提供镜像功能。
超简版命令-所有分支同步!!!
git clone demo.git
cd demo
//拉取所有分支到本地
git branch -r | grep -v '->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
//获取所有tags
git fetch
//新建远程upstream
git remote add upstream 公司内部.git
// 推送当前分支
git push upstream
// 推送其他分支
git branch | grep -v '*' | while read remote; do git checkout "$remote" && git push upstream ; done
//推送所有tag
git psuh upstream --tags
参考
- https://blog.csdn.net/ternence_hsu/article/details/113531510
- https://blog.csdn.net/qq_34273222/article/details/107080031
- https://blog.csdn.net/weixin_44521565/article/details/111246237?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-0.pc_relevant_default&spm=1001.2101.3001.4242.1&utm_relevant_index=3
|