Github项目如何重命名?重命名后继续与本地保持连接
Posted Tisfy.
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Github项目如何重命名?重命名后继续与本地保持连接相关的知识,希望对你有一定的参考价值。
文章目录
想省事儿的可以直接看总结。
Github项目如何重命名
之前正常流程在Github上建立了一个项目,并且已经clone到了本地,也在本地push过了。
但是中途想要修改项目名称,简单修改后本地仓库怕是要找不到upstream,因此记录下了摸索过程。
重命名之前的原始项目
这是原本的项目的创建过程,很正常:
git clone git@github.com:LetMeFly666/EEG-Feature.git
进入目录
cd EEG-Feature
进行修改并提交
git add .
git commit -m "给个Star"
git push
修改项目名称
先是在Github上修改
可以看到修改成功,很轻松
这时候本地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
- 先修改原来的origin为old-origin
git remote rename origin old-origin
- 添加新的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到新地址了。
总结
- 可以直接在Github上修改,并且本地不做任何更改。
这样不好。 git remote rename origin old-origin
重命名旧地址git remote add origin git@github.com:LetMeFly666/MatFeature.git
添加新地址git pull -u origin master
将新地址设为默认。
原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/124348891
以上是关于Github项目如何重命名?重命名后继续与本地保持连接的主要内容,如果未能解决你的问题,请参考以下文章
如何在“GitHub 桌面”上重命名仅限本地的存储库 - 无需重命名存储库目录