在 github 中将 repo 的子目录作为不同的 repo
Fork subdirectory of repo as a different repo in github
我想为 League of Moveable Type's Chunk typeface 以及其他类似任务创建一个 bower 包/样式表。
我想知道是否可以将他们的 "webfonts" 目录分叉到新存储库中的 "fonts" 目录中。这将允许我创建一个 bower.json 文件和样式表。
谢谢,
我不认为你可以直接在网络 UI 上在 github 上分叉它,但如果你可以克隆它并手动推送东西,你可以执行以下操作
克隆存储库
git clone https://github.com/theleagueof/chunk
仅使用文件夹的 git 子树命令创建分支
git subtree split --prefix=folder_name -b new_branch
- 创建一个新的 github 仓库
将这个新的 repo 添加为远程,
git remote add upstream https://github.com/user/repo
推送子树
git push upstream new_branch
Github 在 https://help.github.com/en/articles/splitting-a-subfolder-out-into-a-new-repository:
上发布了如何执行此操作的文章
You can turn a folder within a Git repository into a brand new
repository.
If you create a new clone of the repository, you won't lose any of
your Git history or changes when you split a folder into a separate
repository.
Open Terminal.
Change the current working directory to the location where you want to create your new repository.
Clone the repository that contains the subfolder.
$ git clone https://github.com/USERNAME/REPOSITORY-NAME
- Change the current working directory to your cloned repository.
$ cd REPOSITORY-NAME
To filter out the subfolder from the rest of the files in the repository, run git filter-branch, supplying this information:
FOLDER-NAME: The folder within your project that you'd like to create a separate repository from.
BRANCH-NAME: The default branch for your current project, for example, master or gh-pages.
$ git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME BRANCH-NAME
# Filter the specified branch in your directory and remove empty commits
> Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89)
> Ref 'refs/heads/BRANCH-NAME' was rewritten
The repository should now only contain the files that were in your subfolder.
Create a new repository on GitHub.
At the top of your new GitHub repository's Quick Setup page, click the clipboard to copy the remote repository URL.
- Copy remote repository URL field
Check the existing remote name for your repository. For example, origin or upstream are two common choices.
$ git remote -v
> origin https://github.com/USERNAME/REPOSITORY-NAME.git (fetch)
> origin https://github.com/USERNAME/REPOSITORY-NAME.git (push)
- Set up a new remote URL for your new repository using the existing
remote name and the remote repository URL you copied in step 7.
git remote set-url origin
https://github.com/USERNAME/NEW-REPOSITORY-NAME.git
- Verify that the remote URL has changed with your new repository name.
$ git remote -v
# Verify new remote URL
> origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (fetch)
> origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (push)
- Push your changes to the new repository on GitHub.
git push -u origin BRANCH-NAME
我想为 League of Moveable Type's Chunk typeface 以及其他类似任务创建一个 bower 包/样式表。
我想知道是否可以将他们的 "webfonts" 目录分叉到新存储库中的 "fonts" 目录中。这将允许我创建一个 bower.json 文件和样式表。
谢谢,
我不认为你可以直接在网络 UI 上在 github 上分叉它,但如果你可以克隆它并手动推送东西,你可以执行以下操作
克隆存储库
git clone https://github.com/theleagueof/chunk
仅使用文件夹的 git 子树命令创建分支
git subtree split --prefix=folder_name -b new_branch
- 创建一个新的 github 仓库
将这个新的 repo 添加为远程,
git remote add upstream https://github.com/user/repo
推送子树
git push upstream new_branch
Github 在 https://help.github.com/en/articles/splitting-a-subfolder-out-into-a-new-repository:
上发布了如何执行此操作的文章You can turn a folder within a Git repository into a brand new repository.
If you create a new clone of the repository, you won't lose any of your Git history or changes when you split a folder into a separate repository.
Open Terminal.
Change the current working directory to the location where you want to create your new repository.
Clone the repository that contains the subfolder.
$ git clone https://github.com/USERNAME/REPOSITORY-NAME
- Change the current working directory to your cloned repository.
$ cd REPOSITORY-NAME
To filter out the subfolder from the rest of the files in the repository, run git filter-branch, supplying this information:
FOLDER-NAME: The folder within your project that you'd like to create a separate repository from.
BRANCH-NAME: The default branch for your current project, for example, master or gh-pages.
$ git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME BRANCH-NAME # Filter the specified branch in your directory and remove empty commits > Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89) > Ref 'refs/heads/BRANCH-NAME' was rewritten
The repository should now only contain the files that were in your subfolder.
Create a new repository on GitHub.
At the top of your new GitHub repository's Quick Setup page, click the clipboard to copy the remote repository URL.
- Copy remote repository URL field
Check the existing remote name for your repository. For example, origin or upstream are two common choices.
$ git remote -v > origin https://github.com/USERNAME/REPOSITORY-NAME.git (fetch) > origin https://github.com/USERNAME/REPOSITORY-NAME.git (push)
- Set up a new remote URL for your new repository using the existing remote name and the remote repository URL you copied in step 7.
git remote set-url origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git
- Verify that the remote URL has changed with your new repository name.
$ git remote -v # Verify new remote URL > origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (fetch) > origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (push)
- Push your changes to the new repository on GitHub.
git push -u origin BRANCH-NAME