Skip to content

Commit 49a0827

Browse files
authored
Update splitting-a-subfolder-out-into-a-new-repository.md
https://github.com/actions/.github.git
1 parent cd058f2 commit 49a0827

File tree

1 file changed

+1
-90
lines changed

1 file changed

+1
-90
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,90 +1 @@
1-
---
2-
title: Splitting a subfolder out into a new repository
3-
redirect_from:
4-
- /articles/splitting-a-subpath-out-into-a-new-repository
5-
- /articles/splitting-a-subfolder-out-into-a-new-repository
6-
- /github/using-git/splitting-a-subfolder-out-into-a-new-repository
7-
- /github/getting-started-with-github/splitting-a-subfolder-out-into-a-new-repository
8-
- /github/getting-started-with-github/using-git/splitting-a-subfolder-out-into-a-new-repository
9-
intro: You can turn a folder within a Git repository into a brand new repository.
10-
versions:
11-
fpt: '*'
12-
ghes: '*'
13-
ghae: '*'
14-
ghec: '*'
15-
shortTitle: Splitting a subfolder
16-
---
17-
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.
18-
19-
{% data reusables.command_line.open_the_multi_os_terminal %}
20-
21-
2. Change the current working directory to the location where you want to create your new repository.
22-
23-
4. Clone the repository that contains the subfolder.
24-
```shell
25-
$ git clone https://{% data variables.command_line.codeblock %}/USERNAME/REPOSITORY-NAME
26-
```
27-
28-
4. Change the current working directory to your cloned repository.
29-
```shell
30-
$ cd REPOSITORY-NAME
31-
```
32-
33-
5. To filter out the subfolder from the rest of the files in the repository, install [`git-filter-repo`](https://github.com/newren/git-filter-repo), then run `git filter-repo` with the following arguments.
34-
- `FOLDER-NAME`: The folder within your project where you'd like to create a separate repository.
35-
36-
{% windows %}
37-
38-
{% tip %}
39-
40-
**Tip:** Windows users should use `/` to delimit folders.
41-
42-
{% endtip %}
43-
44-
{% endwindows %}
45-
46-
```shell
47-
$ git filter-repo --path FOLDER-NAME/
48-
# Filter the specified branch in your directory and remove empty commits
49-
> Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89)
50-
> Ref 'refs/heads/BRANCH-NAME' was rewritten
51-
```
52-
53-
The repository should now only contain the files that were in your subfolder(s).
54-
55-
6. [Create a new repository](/repositories/creating-and-managing-repositories/creating-a-new-repository) on {% data variables.product.product_name %}.
56-
57-
7. At the top of your new repository on {% ifversion ghae %}{% data variables.product.product_name %}{% else %}{% data variables.location.product_location %}{% endif %}'s Quick Setup page, click {% octicon "clippy" aria-label="The copy to clipboard icon" %} to copy the remote repository URL.
58-
59-
![Copy remote repository URL field](/assets/images/help/repository/copy-remote-repository-url-quick-setup.png)
60-
61-
{% tip %}
62-
63-
**Tip:** For information on the difference between HTTPS and SSH URLs, see "[About remote repositories](/get-started/getting-started-with-git/about-remote-repositories)."
64-
65-
{% endtip %}
66-
67-
8. Check the existing remote name for your repository. For example, `origin` or `upstream` are two common choices.
68-
```shell
69-
$ git remote -v
70-
> origin https://{% data variables.command_line.codeblock %}/USERNAME/REPOSITORY-NAME.git (fetch)
71-
> origin https://{% data variables.command_line.codeblock %}/USERNAME/REPOSITORY-NAME.git (push)
72-
```
73-
74-
9. 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.
75-
```shell
76-
git remote set-url origin https://{% data variables.command_line.codeblock %}/USERNAME/NEW-REPOSITORY-NAME.git
77-
```
78-
79-
10. Verify that the remote URL has changed with your new repository name.
80-
```shell
81-
$ git remote -v
82-
# Verify new remote URL
83-
> origin https://{% data variables.command_line.codeblock %}/USERNAME/NEW-REPOSITORY-NAME.git (fetch)
84-
> origin https://{% data variables.command_line.codeblock %}/USERNAME/NEW-REPOSITORY-NAME.git (push)
85-
```
86-
87-
11. Push your changes to the new repository on {% data variables.product.product_name %}.
88-
```shell
89-
git push -u origin BRANCH-NAME
90-
```
1+
https://github.com/actions/.github.git

0 commit comments

Comments
 (0)