【GIT】代码仓库服务器变更本地修改并推送

author: jwensh

date: 20231122

问题背景

没有使用域名的 gitlb 服务器搬移(IP地址变了), 以至于 gitlab 管理的项目无法进行连接及推送。因为涉及到多个项目工程,所以可以用本地配置修改的方式来进行重新关联(这种修改 remote 的方式适用于多个平台代码仓库间同步代码

命令行操作方式

old_ip:http://192.168.1.10/jwensh/qadev-ui-testing.git

new_ip:http://192.168.100.1/jwensh/qadev-ui-testing.git

shell 复制代码
# git version 2.39.3 (Apple Git-145)

╰─$ git remote -h
usage: git remote [-v | --verbose]
   or: git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>
   or: git remote rename [--[no-]progress] <old> <new>
   or: git remote remove <name>
   or: git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
   or: git remote [-v | --verbose] show [-n] <name>
   or: git remote prune [-n | --dry-run] <name>
   or: git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
   or: git remote set-branches [--add] <name> <branch>...
   or: git remote get-url [--push] [--all] <name>
   or: git remote set-url [--push] <name> <newurl> [<oldurl>]
   or: git remote set-url --add <name> <newurl>
   or: git remote set-url --delete <name> <url>

    -v, --verbose         be verbose; must be placed before a subcommand

1. 通过命令直接覆盖修改远程地址

进入 qadev-ui-testing 项目的目录下,命令行输入

  • git remote -v查看所有远程仓库
shell 复制代码
origin  http://192.168.1.10/jwensh/qadev-ui-testing.git (fetch)
origin  http://192.168.1.10/jwensh/qadev-ui-testing.git (push)
  • git remote set-url origin http://192.168.100.1/jwensh/qadev-ui-testing.git 直接覆盖修改

2. 通过命令先删除旧的,再添加远程仓库

  • git remote rm origin
  • git remote add origin http://192.168.100.1/jwensh/qadev-ui-testing.git

3. 直接修改配置文件

修改 [remote "origin"] 下面的 url 即可

  • vim qadev-ui-testing/.git/config
shell 复制代码
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = http://192.168.1.10/jwensh/qadev-ui-testing.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
        remote = origin
        merge = refs/heads/main

小建议

如果有些特殊情况想要保留源地址,也就是旧的地址,可以将其改名字(github,gitee)

  • git remote rename origin old_origin 将 origin 更改为 old_origin
  • git remote add origin http://192.168.100.1/jwensh/qadev-ui-testing.git 然后在新添加一个 origin
  • git remote -v 查看
shell 复制代码
old_origin  http://192.168.1.10/jwensh/qadev-ui-testing.git (fetch)
old_origin  http://192.168.1.10/jwensh/qadev-ui-testing.git (push)
origin  	http://192.168.100.1/jwensh/qadev-ui-testing.git (fetch)
origin  	http://192.168.100.1/jwensh/qadev-ui-testing.git (push)
相关推荐
哈喽哈喽哈喽~6 小时前
推送文件到github ---服务器关键配置内容
运维·服务器·经验分享·github
天上飞的粉红小猪6 小时前
linux的文件系统
linux·运维·服务器·1024程序员节
m0_748240257 小时前
基于Reactor模式的高性能C++仿Muduo库:Server服务器模块实现
服务器·c++·php
王同学_1167 小时前
Linux系统端口关闭并排查相关自启动项(麒麟环境)
linux·运维·服务器
q9085447038 小时前
Prometheus+Grafana 智能监控告警系统(服务器指标采集、mysql指标采集)
服务器·grafana·prometheus
郝学胜-神的一滴8 小时前
使用 Python 元类与属性实现惰性加载:Effective Python 第47条
linux·服务器·开发语言·python
袁煦丞 cpolar内网穿透实验室8 小时前
安卓旧机变服务器,KSWEB部署Typecho博客并实现远程访问:cpolar内网穿透实验室第645个成功挑战
android·运维·服务器·远程工作·内网穿透·cpolar
Hefin_H8 小时前
Linux 多用户服务器限制单用户最大内存使用(systemd user.slice)
linux·运维·服务器
G.Chenhui8 小时前
【Macos】安装 macFUSE 和 SSHFS 实现在 Finder 中挂载服务器目录
服务器·macos
饼瑶9 小时前
基于AutoDL远端服务器在pycharm复现:具身智能论文pai0
服务器·elasticsearch·pycharm