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

您所在的位置:网站首页 project怎么修改项目名称和主题 Github项目如何重命名?重命名后继续与本地保持连接

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

2024-06-15 02:07| 来源: 网络整理| 查看: 265

文章目录 Github项目如何重命名重命名之前的原始项目修改项目名称总结

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

Github项目如何重命名

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

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

重命名之前的原始项目

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

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

git clone [email protected]: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 [email protected]:LetMeFly666/EEG-Feature.git (fetch) origin [email protected]: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: [email protected]: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

先修改原来的origin为old-origingit remote rename origin old-origin 添加新的origingit remote add origin [email protected]:LetMeFly666/MatFeature.git

然后输入git remote -v查看:

PS> git remote -v old-origin [email protected]:LetMeFly666/EEG-Feature.git (fetch) old-origin [email protected]:LetMeFly666/EEG-Feature.git (push) origin [email protected]:LetMeFly666/MatFeature.git (fetch) origin [email protected]: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: [email protected]: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到新地址了。

总结 可以直接在Github上修改,并且本地不做任何更改。 这样不好。git remote rename origin old-origin重命名旧地址git remote add origin [email protected]:LetMeFly666/MatFeature.git添加新地址git pull -u origin master将新地址设为默认。

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



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3