可以使用git remote add
命令添加多个远程仓库,具体步骤如下:
-
在命令行终端进入项目根目录
-
输入以下命令添加第一个远程仓库
git remote add <远程仓库名称1> <远程仓库地址1>
例如:
git remote add origin https://github.com/user/repo.git
- 输入以下命令添加第二个远程仓库
git remote add <远程仓库名称2> <远程仓库地址2>
例如:
git remote add backup https://gitlab.com/user/repo.git
- 使用
git remote -v
命令查看当前所有远程仓库
git remote -v
即可看到类似如下的结果:
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
backup https://gitlab.com/user/repo.git (fetch)
backup https://gitlab.com/user/repo.git (push)
这样就添加了两个远程仓库,分别用origin
和backup
来表示。以后就可以使用这两个名称分别向不同的远程仓库推送代码了。