blob: f609e35394eae0c35f2701b68dd4c0a02ec6eb2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
My personal cheatsheet of commands for various tools and workflows
- [Git](#git)
- [Split out subfolder into new repository](#split-out-subfolder-into-new-repository)
- [OLD WAY (git filter-branch)](#old-way-git-filter-branch)
## Git
### Split out subfolder into new repository
Run inside the original repo
```sh
username=tobyvin-cs340
subdir=src/Plotter
newrepo="$(basename $subdir)"
oldrepo="$(pwd)"
git subtree split -P $subdir -b $newrepo
cd $(mktemp -d)
git init && git pull $oldrepo $newrepo
cp $oldrepo/.gitignore ./
cp $oldrepo/.gitattributes ./
git add -A && git commit -m "split out $newrepo into submodule"
gh repo create $username/$newrepo
git push -u origin master
cd $oldrepo
git rm -rf $subdir
rm -rf $subdir
git submodule add git@github.com:$username/$newrepo $subdir
git submodule update --init --recursive
git commit -m "split out $newrepo into submodule"
git push -u origin master
```
### OLD WAY (git filter-branch)
Variables for the original repo and subdirectory you want to split out:
```sh
read -p 'Username: ' username
read -p 'Repo: ' baserepo
read -p 'Folder: ' subdir
newrepo=$(basename $subdir)
```
Clone the repo locally into the new repo name and switch to it:
```sh
git clone git@github.com:$username/$baserepo $newrepo
cd $newrepo
```
Filter repository using filter-branch:
```sh
git filter-branch --subdirectory-filter $subdir -- --all
```
Remove the original remote
```sh
git remote remove origin
```
Create and add new github remote
```sh
gh repo create $username/$newrepo
```
Push changes to new remote
```sh
git push -u origin master
```
|