Files
Linux/Git/GIt多仓库控制.md
offends ce98d5e641
All checks were successful
continuous-integration/drone Build is passing
新增Git操作文档
2025-12-26 21:01:44 +08:00

92 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

> 本文作者:丁辉
# GIt多仓库控制
> 你可以通过添加多个远程仓库,然后从一个远程仓库拉取,推送到另一个远程仓库
## 方法一(添加双远程仓库推荐)
1. 克隆第一个仓库
```bash
git clone <仓库地址>
```
2. 查看当前远程(默认是 origin )
```bash
git remote -v
```
3. 添加第二个仓库,作为另一个远程仓库
```bash
git remote add origin2 <第二个仓库地址>
```
4. 再次查看,现在应该有两个远程仓库
```bash
git remote -v
```
5. 从仓库一拉取最新代码
```bash
git pull origin main
```
6. 修改文件并提交
```bash
git add .
git commit -m "修改说明"
```
7. 推送到仓库二
```bash
git push origin2 main
```
8. 推送完成
## 方法二(单向同步修改现有远程地址)
1. 克隆第一个仓库
```bash
git clone <仓库地址>
```
2. 移除原有的 Origin 远程
```bash
git remote remove origin
```
3. 添加新的仓库作为 Origin
```bash
git remote add origin <新的仓库地址>
```
4. 修改文件并提交
```bash
git add .
git commit -m "修改说明"
```
5. 推送到新的仓库地址
```bash
git push origin main
```
## 注意事项
1. **认证问题**:确保你有两个仓库的推送权限
2. **分支一致性**确认两个仓库使用相同的主分支名main 或 master
3. **冲突处理**:如果两个仓库都有更新,可能需要先合并