首页 > 其他分享 >git改变仓库地址

git改变仓库地址

时间:2023-11-29 23:45:48浏览次数:35  
标签:git iniwu 仓库 gitee 地址 test main Mobini

在管理项目的时候,可能会遇到改变项目仓库地址的情况

为了尽可能的模拟实际开发情况 以github和gitee作为远程仓库

前提:同时为github和gitee配置公钥,并访问正常

为什么要进行地址替换,而不是直接下载新的项目,当改变项目仓库的时候,其实代码的没有太多的变动,新项目所要的相关配置,才是最麻烦的,比如maven仓库,idea设置等等

提前说明方法

方法一:直接修改远程仓库地址

# 查看当前远程仓库
$ git remote -v
origin  [email protected]:iniwym/git.git (fetch)
origin  [email protected]:iniwym/git.git (push)

# 修改远程仓库指向
$ git remote set-url origin [email protected]:iniwym/git.git

# 再次查看
$ git remote -v
origin  [email protected]:iniwym/git.git (fetch)
origin  [email protected]:iniwym/git.git (push)

此时上传和下载都只同步到 gitee

方法二:直接替换.git文件

将源项目的.git文件删除

clone 目标项目

将目标项目的.git文件 直接拷贝到 源项目文件下

在误删(哭)了.git文件的情况下,该方法简单高效

如下是实操过程

确保 github和gitee 公钥 可以正常访问

image-20231129225948242

在github上创建一个项目,并拷贝到本地

在README.md添加一行github

Mobini@iniwu MINGW64 /d/test
$ git clone [email protected]:iniwym/git.git
Cloning into 'git'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.

Mobini@iniwu MINGW64 /d/test
$ cd git/

Mobini@iniwu MINGW64 /d/test/git (main)
$ ll
total 1
-rw-r--r-- 1 Mobini 197121 5 Nov 29 21:55 README.md

Mobini@iniwu MINGW64 /d/test/git (main)
$ vim README.md

Mobini@iniwu MINGW64 /d/test/git (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

Mobini@iniwu MINGW64 /d/test/git (main)
$ git add .
warning: in the working copy of 'README.md', LF will be replaced by CRLF the next time Git touches it

Mobini@iniwu MINGW64 /d/test/git (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md

Mobini@iniwu MINGW64 /d/test/git (main)
$ git commit -m "github"
[main 170ac4e] github
 1 file changed, 3 insertions(+), 1 deletion(-)

Mobini@iniwu MINGW64 /d/test/git (main)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 284 bytes | 284.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:iniwym/git.git
   0dd4a1f..170ac4e  main -> main

使用gitee导入github的仓库,模拟更换后的仓库地址

image-20231127224155907

下载gitee相同项目

并在README.md添加一行github基础上

添加一行 gitee

Mobini@iniwu MINGW64 /d/test/gitee
$ git clone [email protected]:iniwym/git.git
Cloning into 'git'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 7 (delta 0), reused 7 (delta 0), pack-reused 0
Receiving objects: 100% (7/7), done.

Mobini@iniwu MINGW64 /d/test/gitee
$ cd git/

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ vim README.md

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ git add .

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ git commit -m "gitee"
[main a3d7e72] gitee
 1 file changed, 2 insertions(+)

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 289 bytes | 289.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:iniwym/git.git
   170ac4e..a3d7e72  main -> main

方法一 修改远程仓库指向

# 查看当前远程仓库
Mobini@iniwu MINGW64 /d/test/git (main)
$ git remote -v
origin  [email protected]:iniwym/git.git (fetch)
origin  [email protected]:iniwym/git.git (push)

# 修改远程仓库指向
Mobini@iniwu MINGW64 /d/test/git (main)
$ git remote set-url origin [email protected]:iniwym/git.git

# 再次查看
Mobini@iniwu MINGW64 /d/test/git (main)
$ git remote -v
origin  [email protected]:iniwym/git.git (fetch)
origin  [email protected]:iniwym/git.git (push)

#更新
Mobini@iniwu MINGW64 /d/test/git (main)
$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 269 bytes | 22.00 KiB/s, done.
From gitee.com:iniwym/git
   170ac4e..a3d7e72  main       -> origin/main
Updating 170ac4e..a3d7e72
Fast-forward
 README.md | 2 ++
 1 file changed, 2 insertions(+)

Mobini@iniwu MINGW64 /d/test/git (main)
$ vim README.md

Mobini@iniwu MINGW64 /d/test/git (main)
$ git add .

Mobini@iniwu MINGW64 /d/test/git (main)
$ git commit -m "for github project"
[main 67fe3e9] for github project
 1 file changed, 1 insertion(+), 1 deletion(-)

Mobini@iniwu MINGW64 /d/test/git (main)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 300 bytes | 300.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:iniwym/git.git
   a3d7e72..67fe3e9  main -> main



结果

image-20231129232750543

image-20231129232852999

方法二

直接替换 .git文件

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ git remote -v
origin  [email protected]:iniwym/git.git (fetch)
origin  [email protected]:iniwym/git.git (push)

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ git pull
Already up to date.

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ vim README.md

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ git add .

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ git commit -m "for gitee project"
[main 7be8859] for gitee project
 1 file changed, 3 insertions(+), 1 deletion(-)

Mobini@iniwu MINGW64 /d/test/gitee/git (main)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 299 bytes | 299.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:iniwym/git.git
   170ac4e..7be8859  main -> main

结果

image-20231129232815151

image-20231129232911824

image-20231129233229218

end

标签:git,iniwu,仓库,gitee,地址,test,main,Mobini
From: https://www.cnblogs.com/iniwym/p/17866218.html

相关文章

  • 同时为github和gitee配置公钥
    同时为github和gitee配置公钥1.下载githttps://git-scm.com/download/win2.配置公钥参考https://help.gitee.com/base/account/SSH公钥设置通过命令ssh-keygen生成SSHKey:ssh-keygen-ted25519-C"[email protected]"输入秘钥文件名,其他回车id_rsa_githubid......
  • git
    gitstatusgitstatus-s--ignored//以简洁模式查看暂存区和工作区的文件(全部显示,不执行文件过滤)gitstatus-uno//查看暂存区和工作区的非untrack(未跟踪)状态文件gitstatus-uall//查看暂存区和工作区的状态文件(递归子目录显示出里面的文件)查看log显示log同时显示......
  • 斜率优化 [ZJOI2007] 仓库建设
    [ZJOI2007]仓库建设题目描述L公司有\(n\)个工厂,由高到低分布在一座山上,工厂\(1\)在山顶,工厂\(n\)在山脚。由于这座山处于高原内陆地区(干燥少雨),L公司一般把产品直接堆放在露天,以节省费用。突然有一天,L公司的总裁L先生接到气象部门的电话,被告知三天之后将有一场暴雨,于......
  • Gitee - 基于 Git 的代码托管和研发协作平台本地代码同步教程
    什么是Gitee?一、Gitee的发展史。Gitee(码云)是开源中国于2013年推出的基于Git的代码托管平台、企业级研发效能平台,提供中国本土化的代码托管服务。二、个人对Gitee的理解Gitee跟Git有什么区别,个人认为一个是国内、一个是国外,但是两个的目的都是一样的,都是为了方便彼此更好的代......
  • 极狐GitLab—新一代源代码管理仓库
    产品概述    极狐GitLab是一款具有软件开发全生命周期的DevOps能力的新一代源代码管理仓库,无缝集成代码托管、敏捷管理、CI/CD,从需求管理到应用上线能够形成数据的完整串联。极狐GitLab具有高可用可扩展的架构特点,可提供万人规模的架构行业实践参考和专业服务支持;提供专业......
  • 数据仓库理论
    数据仓库理论数仓是一种思想,数仓是一种规范,数仓是一种解决方案!1、数据处理方式数据处理大致可以分为两大类:联机事务处理:OLTP(On_LineTransactionProcessing)、联机分析处理OLAP(On_LineAnalyticalProcessing)OLTP(On_LineTransactionsProcessing):中文名称是联机......
  • 解决git status报错问题,以及git init初始化不成功问题
    VbenAdmin安装依赖时husky安装失败请查看你的源码是否从github直接下载的,直接下载是没有.git文件夹的,而husky需要依赖git才能安装。此时需使用gitinit初始化项目,再尝试重新安装即可。 在你要做的项目的文件夹中,空白区域右击鼠标,属性-安全-完全控制权限给允许......
  • FastGit 和 nvm 配合使用
    背景研究一个前端项目(itcase<苍穹外卖>)的时,发现node版本执行npminstall出现依赖下载失败等等问题解决办法1.启动FastGit2.安装nvm(node版本管理工具)##https://blog.csdn.net/muguli2008/article/details/107730766nvmlistavailable#百度下nvminstall12.2......
  • 快速解决Error: error:0308010C:digital envelope routines::unsupported的三种解决方
    问题描述:    报错:Error:error:0308010C:digitalenveloperoutines::unsupported报错原因:     因为node.jsV17版本中最近发布的OpenSSL3.0,而OpenSSL3.0对允许算法和密钥大小增加了严格的限制报错详细信息:解决方案: 方案1:打开IDEA终端,直接输入Linux&......
  • C#删除.git文件夹
    C#在通常情况下删除文件只需要调用下面的方法即可:Directory.Delete(dir.FullName,true);上面的代码会删除指定的文件夹及文件夹下面所有的子文件夹和文件。但是用上面的代码去删除.git文件夹的目录时,貌似会失败,报异常。具体的失败原因不是特别清楚,也没有去仔细钻研。可能的......