1.进入项目根目录
cd /www/repo
2.如果没有初始化则请输入命令完成初始化
git init
3.如果已配置过git远程仓库,请移除
git remote rm origin
4.依次添加多个远程仓库地址
git remote add github git@github.com:org/repo.git
git remote add gitee git@gitee.com:org/repo.git
5.配置当前项目的用户名和邮箱
git config user.name Tom
git config user.email tom@github.com
6.查看.git/config配置信息
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[branch "master"]
[remote "github"]
url = git@github.com:org/repo.git
fetch = +refs/heads/*:refs/remotes/github/*
[remote "gitee"]
url = git@gitee.com:org/repo.git
fetch = +refs/heads/*:refs/remotes/gitee/*
[user]
email = tom@github.com
7.推送/拉取代码示例(原本默认存在的origin被命名为github和gitee)
// 分别执行github和gitee两个远程仓库的拉取和推送操作,例:
git push github master
git push github test
git pull github master
git push gitee master
git pull gitee master
8.使用 git remote -v 查看远程仓库
/www/repo> git remote -v
github git@github.com:org/repo.git (fetch)
github git@github.com:org/repo.git (push)
gitee git@gitee.com:org/repo.git (fetch)
gitee git@gitee.com:org/repo.git (push)
9.如果遇到如下问题,可参考:
Q1: ! [rejected] master -> master (non-fast-forward)……
A1:git pull gitee master --allow-unrelated-histories
Q2:fatal:refusing to merge unrelated histories ……(拒绝合并无关的历史)
A2:
(1)将本地仓库和远程长裤分支做好映射
git branch --set-upstream-to=origin/remote_branch your_local_branch
(2)整合远程仓库和本地仓库(忽略版本不同造成的影响)
git pull --allow-unrelated-histories
10.删除远程仓库就变成了git remote rm gitee或git remote rm github