Github项目如何重命名?重命名后继续与本地保持连接

本文详细指导了如何在Github上重命名已有的项目,包括原项目克隆、远程仓库操作、分支管理及避免冲突的过程,适合开发者查阅。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


想省事儿的可以直接看总结


Github项目如何重命名

之前正常流程在Github上建立了一个项目,并且已经clone到了本地,也在本地push过了。

但是中途想要修改项目名称,简单修改后本地仓库怕是要找不到upstream,因此记录下了摸索过程。

重命名之前的原始项目

这是原本的项目的创建过程,很正常:

创建项目
创建项目2
复制SSH地址

git clone git@github.com:LetMeFly666/EEG-Feature.git

进入目录

cd EEG-Feature

进行修改并提交

git add .
git commit -m "给个Star"
git push

修改项目名称

先是在Github上修改

设置
Rename
可以看到修改成功,很轻松
修改成功
这时候本地git的remote还是老的EEG-Feature

PS> git remote -v
origin  git@github.com:LetMeFly666/EEG-Feature.git (fetch)
origin  git@github.com:LetMeFly666/EEG-Feature.git (push)

但是这个时候直接

PS> git add .
PS> git commit -m "如果直接不加更改"
PS> git push
Enumerating objects: 5, done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 333 bytes | 333.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote: This repository moved. Please use the new location:
remote:   git@github.com:LetMeFly666/MatFeature.git
To github.com:LetMeFly666/EEG-Feature.git
   b1cea07..bbd6747  master -> master

可以看到旧地址还是可以访问的

如果直接访问旧地址https://github.com/LetMeFly666/EEG-Feature,会直接redirect到新地址https://github.com/LetMeFly666/MatFeature

此时想建立新项目名叫EEG-Feature仍然是可以的
此名称仍然可以使用

为了防止以后建立名为EEG-Feature的项目产生冲突,决定还是直接修改upstream

  1. 先修改原来的origin为old-origin
    git remote rename origin old-origin
    
  2. 添加新的origin
    git remote add origin git@github.com:LetMeFly666/MatFeature.git
    

然后输入git remote -v查看:

PS> git remote -v
old-origin      git@github.com:LetMeFly666/EEG-Feature.git (fetch)
old-origin      git@github.com:LetMeFly666/EEG-Feature.git (push)
origin  git@github.com:LetMeFly666/MatFeature.git (fetch)
origin  git@github.com:LetMeFly666/MatFeature.git (push)

再修改一些文件提交试试,发现直接git push还是会push到旧地址

PS> git add .
PS> git commit -m "直接git push"
[master f99f787] 直接git push
 1 file changed, 1 insertion(+)
PS> git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 343 bytes | 343.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote: This repository moved. Please use the new location:
remote:   git@github.com:LetMeFly666/MatFeature.git
To github.com:LetMeFly666/EEG-Feature.git
   bbd6747..f99f787  master -> master

因此必须指定默认push分支

PS> git add .
PS> git commit -m "-u指定"
[master f99f787] "-u指定"
PS> git push -u origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 405 bytes | 405.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:LetMeFly666/MatFeature.git
   f99f787..6b2e285  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

默认分支设置成功

再次push就直接push到新地址了。

总结

  1. 可以直接在Github上修改,并且本地不做任何更改。
    这样不好。
  2. git remote rename origin old-origin重命名旧地址
  3. git remote add origin git@github.com:LetMeFly666/MatFeature.git添加新地址
  4. git pull -u origin master将新地址设为默认。

原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/124348891

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tisfy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值