git中,项目怎么更换远程仓库连接地址

1.需求背景:公司将GitLab的ip地址更改,原来拉下来的项目都需要更换成新的地址,否则无法推送和拉取代码

2.实现过程

2.1 方法1:直接修改远程 URL(推荐)

bash 复制代码
# 查看当前远程仓库地址
git remote -v

# 修改远程仓库 URL
git remote set-url origin <新的仓库地址>

# 例如:
git remote set-url origin https://github.com/username/new-repo.git
# 或 SSH 方式:
git remote set-url origin git@github.com:username/new-repo.git

2.2 方法2:先删除再添加

bash 复制代码
# 删除现有的 origin 远程仓库
git remote rm origin

# 添加新的远程仓库地址
git remote add origin <新的仓库地址>
相关推荐
言之。7 小时前
Git Hooks
git
代码AI弗森8 小时前
Git Bash 与 PowerShell:定位差异、使用场景与选择建议
开发语言·git·bash
森叶10 小时前
Git flow command error: ‘flow‘ is not a git command 问题解决
git
天麓11 小时前
git merge 举例
git
AI_567812 小时前
Git冲突治理白皮书:智能标记与可视化协同的下一代解决方案
大数据·人工智能·git·机器学习
念丶小宇13 小时前
Git常用指令
大数据·git·elasticsearch
CSDN_RTKLIB13 小时前
Git Clone
git
中二病码农不会遇见C++学姐13 小时前
.env 文件是干啥的?为什么不能提交到 Git?
git·学习
CoderJia程序员甲14 小时前
GitHub 热榜项目 - 日榜(2026-02-03)
git·ai·开源·llm·github