You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Git仓库URL中的/tree/main/路径段?

移除GitHub路径中/tree/main/部分的可行方案

GitHub的URL规则里,仓库下的子目录默认必须通过/tree/分支名/来标识具体分支下的目录,无法直接去掉这部分,但可以通过以下两种方式实现接近你期望的简洁路径:

方案一:调整仓库目录结构(推荐)

把Cybersecurity目录的内容移到仓库根目录,这样访问仓库主页就直接展示原Cybersecurity的内容,操作步骤:

  • 本地克隆仓库(未克隆过的话):
    git clone https://github.com/omarjuvera/Portfolios.git
    cd Portfolios
    
  • 将Cybersecurity内的所有文件(包括隐藏文件)移到仓库根目录:
    mv Cybersecurity/* .
    mv Cybersecurity/.* .
    
  • 删除空的Cybersecurity文件夹:
    rmdir Cybersecurity
    
  • 提交修改并推送到远程仓库:
    git add .
    git commit -m "Migrate Cybersecurity content to repo root"
    git push origin main
    

完成后,访问https://github.com/omarjuvera/Portfolios就等同于原来的/tree/main/Cybersecurity路径,仓库内文件的访问路径也会去掉Cybersecurity前缀。

方案二:拆分出独立仓库

如果想保留原Portfolios仓库结构,同时获得无/tree/main/的独立路径,可以把Cybersecurity拆分为单独的GitHub仓库:

  • 本地克隆原仓库:
    git clone https://github.com/omarjuvera/Portfolios.git
    cd Portfolios
    
  • 拆分Cybersecurity目录为独立分支:
    git subtree split --prefix Cybersecurity -b cybersecurity-branch
    
  • 在GitHub创建新的Cybersecurity仓库,将拆分出的分支推送到新仓库:
    git remote add cybersecurity-repo https://github.com/omarjuvera/Cybersecurity.git
    git push cybersecurity-repo cybersecurity-branch:main
    

完成后,新仓库的访问路径就是https://github.com/omarjuvera/Cybersecurity,完全不带/tree/main/部分。

内容的提问来源于stack exchange,提问作者Omar Juvera

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 16:01:15