computing:git
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| computing:git [2026/04/27 18:14] – [Getting Started] oscar | computing:git [2026/04/27 18:54] (current) – oscar | ||
|---|---|---|---|
| Line 105: | Line 105: | ||
| |Pull changes and then rebase your current branch|git pull --rebase| | |Pull changes and then rebase your current branch|git pull --rebase| | ||
| |Pull changes and then merge them into your current branch|git pull origin main OR \\ git pull| | |Pull changes and then merge them into your current branch|git pull origin main OR \\ git pull| | ||
| + | |||
| + | ==== Submodules ==== | ||
| + | === Adding a Submodule === | ||
| + | Navigate to the root directory of ‘main-project’ and run the following command: | ||
| + | git submodule add < | ||
| + | This command adds ‘mysubmodule’ as a submodule to ‘main-project’. It clones ‘mysubmodule’ into a subdirectory of ‘main-project’ and creates a special file called **.gitmodules**. This file tracks the mapping between the project URL and the local subdirectory you've pulled it into. | ||
| + | |||
| + | After adding the submodule, you need to commit this change to your repository: | ||
| + | git commit -m "Added util-methods submodule" | ||
| + | |||
| + | Now, you can import and use function from ' | ||
| + | |||
| + | === Updating a Submodule === | ||
| + | Navigate to the ‘mysubmodule’ directory within ‘main-project’ and pull the latest changes: | ||
| + | cd mysubmodule | ||
| + | git pull origin master | ||
| + | |||
| + | After pulling the latest changes, navigate back to the root directory of ‘main-project’ and commit this update: | ||
| + | cd .. | ||
| + | git commit -m " | ||
| + | |||
| + | Alternatively, | ||
| + | |||
| + | === Submodule Caveats === | ||
| + | There are some caveats and things to keep in mind when using Git submodules: | ||
| + | |||
| + | * Updating: Submodules do not automatically stay in sync with the remote repository. You need to go into each submodule and pull the changes manually. | ||
| + | * Committing: If you make changes inside a submodule, you need to commit those changes within the submodule first, then go to the main repository and commit the change to the submodule. This is because the main repository tracks the submodule’s commit. | ||
| + | * Cloning: When you clone a repository, the submodules will not be cloned along with it. You need to use git submodule update --init --recursive or git clone --recursive < | ||
| + | * Pulling: Similarly, when you pull your main repository, it will not pull the new commits of populated submodules. Use the --recurse-submodules option with the git pull to update all the submodules as well. | ||
| ==== Important Files ==== | ==== Important Files ==== | ||
computing/git.1777313659.txt.gz · Last modified: by oscar
