Add submodule snippets

This commit is contained in:
Chalarangelo
2021-04-08 20:05:15 +03:00
parent 298abe80b7
commit e28b27604d
4 changed files with 75 additions and 0 deletions

18
snippets/add-submodule.md Normal file
View File

@ -0,0 +1,18 @@
---
title: Add a submodule
tags: repository,submodule,advanced
---
Adds a new submodule to the repository.
- Use `git submodule add <upstream-path> <local-path>` to add a new submodule from `<upstream-path>` to `<local-path>`.
```sh
git submodule add <upstream-path> <local-path>
```
```sh
git submodule add https://github.com/30-seconds/30-seconds-of-code ./30code
# Creates the directory `30code` containing the submodule from
# "https://github.com/30-seconds/30-seconds-of-code"
```

View File

@ -0,0 +1,17 @@
---
title: Clone missing submodules
tags: repository,submodule,advanced
---
Clones missing submodules and checks out commits.
- Use `git submodule update --init --recursive` to clone missing submodules and checkout commits.
```sh
git submodule update --init --recursive
```
```sh
git submodule update --init --recursive
# Clones missing submodules and checks out commits
```

View File

@ -0,0 +1,23 @@
---
title: Delete a submodule
tags: repository,submodule,advanced
---
Deletes a submodule from the repository.
- Use `git submodule deinit -f -- <submodule>` to unregister the specified `<submodule>`.
- Use `rm -rf .git/modules/<submodule>` to remove the directory of the submodule.
- Use `git rm -f <submodule>` to remove the working tree of the submodule.
```sh
git submodule deinit -f -- <submodule>
rm -rf .git/modules/<submodule>
git rm -f <submodule>
```
```sh
git submodule deinit -f -- 30code
rm -rf .git/modules/30code
git rm -f 30code
# Removes the `30code` submodule
```

View File

@ -0,0 +1,17 @@
---
title: Pull all submodules from remote
tags: repository,submodule,advanced
---
Pulls all submodules from their respective remotes.
- Use `git submodule update --recursive --remote` to pull all submodules from their respective remotes.
```sh
git submodule update --recursive --remote
```
```sh
git submodule update --recursive --remote
# Pulls all submodules from their respective remotes
```