最近进行了git仓库迁移,将git代码从自建的gitlab仓库,转移到阿里云的“云效”管理平台。

阿里云-云效

同步仓库

1
2
3
4
5
git clone --mirror https://github.com/xxxxxxx/oldProject.git

git remote set-url origin https://github.com/xxxxxxx/newProject.git

git push --mirror

拉取所有分支

Git 远程同步

git 拉取远程所有分支

1
2
3
4
5
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done

git fetch --all && git pull --all
git remote set-url origin git@192.168.1.237:algo/chicona_clean.git
git push --all

submodule

拉取子仓库

Git submodule update —init

一次性Clone项目和Submodules
git clone --recursive /path/to/repos/foo.git

查看commit所属分支

git查看一个commit属于哪个分支
git branch -r --contains COMMIT_ID

可能错误

The remote end hung up unexpectedly

在使用git更新或提交项目时候出现 “fatal: The remote end hung up unexpectedly “ 原因是推送的文件太大。

修改提交缓存大小为500M,或者更大的数字

git config --global http.postBuffer 524288000

或者在克隆/创建版本库生成的 .git目录下面修改生成的config文件增加如下:

1
2
[http]  
postBuffer = 524288000

如何解决failed to push some refs to git

出现错误的主要原因是github中的README.md文件不在本地代码目录中

可以通过如下命令进行代码合并【注:pull=fetch+merge]

git pull --rebase origin master

执行上面代码后可以看到本地代码库中多了README.md文件