debian-mirror-gitlab/doc/university/training/topics/subtree.md

50 lines
1.3 KiB
Markdown
Raw Normal View History

2018-03-17 18:26:18 +05:30
---
comments: false
---
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
# Subtree
2017-08-17 22:00:37 +05:30
2019-03-02 22:35:43 +05:30
- Used when there are nested repositories.
- Not recommended when the amount of dependencies is too large.
- For these cases we need a dependency control system.
- Command are painfully long so aliases are necessary.
2017-08-17 22:00:37 +05:30
## Subtree Aliases
2020-04-08 14:13:33 +05:30
- Add: `git subtree add --prefix <target-folder> <url> <branch> --squash`
- Pull: `git subtree pull --prefix <target-folder> <url> <branch> --squash`
- Push: `git subtree add --prefix <target-folder> <url> <branch>`
2019-09-04 21:01:54 +05:30
- Ex: `git config alias.sbp 'subtree pull --prefix st /
2020-04-08 14:13:33 +05:30
git@gitlab.com:balameb/subtree-nested-example.git master --squash'`
2017-08-17 22:00:37 +05:30
2020-03-09 13:42:32 +05:30
```shell
2017-08-17 22:00:37 +05:30
# Add an alias
# Add
git config alias.sba 'subtree add --prefix st /
git@gitlab.com:balameb/subtree-nested-example.git master --squash'
# Pull
git config alias.sbpl 'subtree pull --prefix st /
git@gitlab.com:balameb/subtree-nested-example.git master --squash'
# Push
git config alias.sbph 'subtree push --prefix st /
git@gitlab.com:balameb/subtree-nested-example.git master'
# Adding this subtree adds a st dir with a readme
git sba
vi st/README.md
# Edit file
git status shows differences
```
2020-03-09 13:42:32 +05:30
```shell
2017-08-17 22:00:37 +05:30
# Adding, or committing won't change the sub repo at remote
# even if we push
git add -A
git commit -m "Adding to subtree readme"
# Push to subtree repo
git sbph
# now we can check our remote sub repo
```