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

如何创建仅含Initial commit的Git public分支并推送到公开仓库

创建无历史提交的Git公开分支
  • 切换到本地master分支并确保代码最新:

    git checkout master
    git pull
    
  • 创建无提交历史的public分支:

    git checkout --orphan public
    

    该分支会继承master当前的文件内容,但完全独立于原有提交历史。

  • (可选)若需要清理文件重新整理,执行以下命令清空暂存区:

    git rm -rf .
    
  • 将当前文件添加到暂存区:

    git add .
    
  • 提交初始版本:

    git commit -m "Initial commit"
    
  • 推送到公开远程仓库(替换public-remote为你实际添加的公开远程名称):

    git push -u public-remote public
    

后续同步master更新到public分支

  • 拉取master最新代码:
    git checkout master
    git pull
    
  • 切换到public分支并合并更新(squash会将所有更新合并为单个提交):
    git checkout public
    git merge master --squash
    git commit -m "Sync latest updates from master"
    git push public-remote public
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 19:35:14