You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/get-started/using-git/splitting-a-subfolder-out-into-a-new-repository.md
+43-34Lines changed: 43 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,65 +17,74 @@ shortTitle: Splitting a subfolder
17
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
18
19
19
{% data reusables.command_line.open_the_multi_os_terminal %}
20
+
20
21
2. Change the current working directory to the location where you want to create your new repository.
21
-
3. Clone the repository that contains the subfolder.
22
-
```shell
23
-
$ git clone https://{% data variables.command_line.codeblock %}/<em>USERNAME</em>/<em>REPOSITORY-NAME</em>
24
-
```
22
+
23
+
4. Clone the repository that contains the subfolder.
24
+
```shell
25
+
$ git clone https://{% data variables.command_line.codeblock %}/<em>USERNAME</em>/<em>REPOSITORY-NAME</em>
26
+
```
27
+
25
28
4. Change the current working directory to your cloned repository.
26
-
```shell
27
-
$ cd<em>REPOSITORY-NAME</em>
28
-
```
29
+
```shell
30
+
$ cd<em>REPOSITORY-NAME</em>
31
+
```
32
+
29
33
5. To filter out the subfolder from the rest of the files in the repository, run [`git filter-repo`](https://github.com/newren/git-filter-repo), supplying this information:
30
34
-`FOLDER-NAME`: The folder within your project where you'd like to create a separate repository.
31
35
32
-
{% windows %}
36
+
{% windows %}
33
37
34
-
{% tip %}
38
+
{% tip %}
35
39
36
-
**Tip:** Windows users should use `/` to delimit folders.
40
+
**Tip:** Windows users should use `/` to delimit folders.
> Ref 'refs/heads/<em>BRANCH-NAME</em>' was rewritten
47
51
```
48
-
The repository should now only contain the files that were in your subfolder(s).
52
+
53
+
The repository should now only contain the files that were in your subfolder(s).
49
54
50
55
6.[Create a new repository](/articles/creating-a-new-repository/) on {% data variables.product.product_name %}.
56
+
51
57
7. At the top of your new repository on {% ifversion ghae %}{% data variables.product.product_name %}{% else %}{% data variables.product.product_location %}{% endif %}'s Quick Setup page, click {% octicon "clippy" aria-label="The copy to clipboard icon" %} to copy the remote repository URL.
**Tip:** For information on the difference between HTTPS and SSH URLs, see "[About remote repositories](/github/getting-started-with-github/about-remote-repositories)."
63
+
**Tip:** For information on the difference between HTTPS and SSH URLs, see "[About remote repositories](/github/getting-started-with-github/about-remote-repositories)."
57
64
58
-
{% endtip %}
65
+
{% endtip %}
59
66
60
67
8. Check the existing remote name for your repository. For example, `origin` or `upstream` are two common choices.
61
-
```shell
62
-
$ git remote -v
63
-
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/REPOSITORY-NAME</em>.git (fetch)
64
-
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/REPOSITORY-NAME</em>.git (push)
65
-
```
68
+
```shell
69
+
$ git remote -v
70
+
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/REPOSITORY-NAME</em>.git (fetch)
71
+
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/REPOSITORY-NAME</em>.git (push)
72
+
```
66
73
67
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.
68
-
```shell
69
-
git remote set-url origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/NEW-REPOSITORY-NAME</em>.git
70
-
```
75
+
```shell
76
+
git remote set-url origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/NEW-REPOSITORY-NAME</em>.git
77
+
```
78
+
71
79
10. Verify that the remote URL has changed with your new repository name.
72
-
```shell
73
-
$ git remote -v
74
-
# Verify new remote URL
75
-
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/NEW-REPOSITORY-NAME</em>.git (fetch)
76
-
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/NEW-REPOSITORY-NAME</em>.git (push)
77
-
```
80
+
```shell
81
+
$ git remote -v
82
+
# Verify new remote URL
83
+
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/NEW-REPOSITORY-NAME</em>.git (fetch)
84
+
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/NEW-REPOSITORY-NAME</em>.git (push)
85
+
```
86
+
78
87
11. Push your changes to the new repository on {% data variables.product.product_name %}.
0 commit comments