我想克隆 git 存储库的特定分支并将其复制到我自己的私有 git 存储库。原始存储库非常巨大,并且有很多分支,我根本不需要。我也不需要任何文件历史记录。分叉不是一种选择,因为分叉的存储库在 github 上不允许是私有的。
运行后
git clone https://example.com/repo.git -b my-branch
Run Code Online (Sandbox Code Playgroud)
如何删除本地副本中所有特定于 git 的信息,只保留 my-branch,就像我刚刚创建了包含的文件一样?
您只需删除该.git目录并重新初始化存储库即可。
rm -rf .git # Delete all git information
git init # Recreate an empty repo
git add --all # Re-add all the files to the index
git commit -m 'Initial fork from example.com/repo.git'
Run Code Online (Sandbox Code Playgroud)