computing:git
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| computing:git [2026/04/26 19:06] – [Merge Conflicts] oscar | computing:git [2026/04/27 18:54] (current) – oscar | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ^Task^Command^ | ^Task^Command^ | ||
| |Start a new repo|git init| | |Start a new repo|git init| | ||
| - | |Clone an existing repo|git clone < | + | |Clone an existing repo|git clone <url> \\ git clone http:// |
| ==== Configure Git ==== | ==== Configure Git ==== | ||
| ^Task^Command^ | ^Task^Command^ | ||
| Line 35: | Line 35: | ||
| |Commit all unstaged changes|git commit -am ' | |Commit all unstaged changes|git commit -am ' | ||
| - | ==== Move Between | + | ==== Branches ==== |
| ^Task^Command^ | ^Task^Command^ | ||
| - | |Switch branches|git switch < | ||
| - | |Create a branch|git branch < | ||
| |List branches|git branch| | |List branches|git branch| | ||
| |List branches by most recently committed to|git branch --sort=-committerdate| | |List branches by most recently committed to|git branch --sort=-committerdate| | ||
| + | |Switch branches|git switch < | ||
| + | |Create a branch|git branch < | ||
| |Delete a branch|git branch -d < | |Delete a branch|git branch -d < | ||
| |Force delete a branch|git branch -D < | |Force delete a branch|git branch -D < | ||
| Line 75: | Line 75: | ||
| ^Task^Command^ | ^Task^Command^ | ||
| |Show the files under control|git ls-files| | |Show the files under control|git ls-files| | ||
| - | |Look at a branch' | + | |Look at a branch' |
| |Show every commit that modified a file| git log < | |Show every commit that modified a file| git log < | ||
| |Show every commit that modified a file, including before it was renamed| git log --follow < | |Show every commit that modified a file, including before it was renamed| git log --follow < | ||
| Line 83: | Line 83: | ||
| ==== Combine Diverged Branches ==== | ==== Combine Diverged Branches ==== | ||
| ^Task^Command^ | ^Task^Command^ | ||
| + | |Abort a merge|git merge --abort| | ||
| |Combine with Rebase|git switch banana \\ git rebase main \\ \\ Before \\ {{ : | |Combine with Rebase|git switch banana \\ git rebase main \\ \\ Before \\ {{ : | ||
| |Combine with Merge|git switch main \\ git merge banana \\ \\ Before \\ {{ : | |Combine with Merge|git switch main \\ git merge banana \\ \\ Before \\ {{ : | ||
| Line 104: | 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.1777230399.txt.gz · Last modified: by oscar
