git 更换远程仓库地址三种方法总结

git 更换远程仓库地址三种方法总结

一、前言

由于私服的 gitlab 的地址变更,导致部分项目代码提交不上去,需要修改远端仓地址。

其它需要修改远程仓地址的情况如:切换git clone 协议由ssh变为https。

二、环境

  • windows 10
  • git version 2.34.0.windows.1

三、帮助文档

四、三种修改方法

方法一:不删除远程仓库修改(最方便)

复制代码
# 查看远端地址
git remote -v  
# 查看远端仓库名
git remote 
# 重新设置远程仓库
git remote set-url origin https://gitee.com/xx/xx.git (新地址)

方法二:删除远程仓库修改(可能有问题?)

复制代码
# 删除远程的仓库
git remote rm origin
# 重新添加远程仓库
git remote add origin  https://gitee.com/xx/xx.git(新地址) 

方法三:修改 .git 文件夹修改(不用敲命令行)

打开项目目录下隐藏文件夹.git下的config文件内容,将 [remote "origin"] url 修改成你需要替换的新地址:

新地址:

复制代码
[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[submodule]
	active = .
[remote "origin"]
	url = https://gitee.com/xx/xx.git(新地址)  
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
相关推荐
q5431470871 分钟前
Redis Desktop Manager(Redis可视化工具)安装及使用详细教程
redis·git·bootstrap
素雨迁喜1 小时前
Linux平台下git工具的使用
linux·运维·git
Irene19913 小时前
Windows环境,VS Code 中 Git 配置指南
git·基础配置
Yang-Never4 小时前
AI Code -> Windows电脑安装Claude
开发语言·windows·git
Irene19914 小时前
2026 前端开发 Windows 安装 Git 配置指南(有实际安装过程参考:适配版本 the latest 2.53.0(2) x64 )
前端·windows·git
早起的年轻人5 小时前
告别Git仓库臃肿:一招解决Maven target目录误提交问题
java·git·maven
悠然大月季21 小时前
git 怎么导出提交历史,文件是乱码
git·git导出历史记录·git导出历史乱码
chenshiming8021 天前
在cursor下执行GIT回退版本
git
打点计时器1 天前
Git快速上手教程
git
我才是一卓1 天前
linux 安装简易 git 服务端并使用
linux·运维·git