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
# 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
查看所有遠程倉庫
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
[core]repositoryformatversion = 0filemode = truebare = falselogallrefupdates = trueignorecase = trueprecomposeunicode = true
[remote "origin"]url = http://192.168.1.10/jwensh/qadev-ui-testing.gitfetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]remote = originmerge = refs/heads/main
小建議
如果有些特殊情況想要保留源地址,也就是舊的地址,可以將其改名字(github,gitee)
git remote rename origin old_origin
將 origin 更改為 old_origingit remote add origin http://192.168.100.1/jwensh/qadev-ui-testing.git
然后在新添加一個 origingit remote -v
查看
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)