## Repository Management | Command | Description | | --------------------------------------------- | ---------------------------------------------------------- | | `git init` | Initialize a new Git repository | | `git clone <url>` | Clone a remote repository | | `git status` | Show the working tree status | | `git add <file>` | Add a file to the staging area | | `git commit -m <message>` | Commit changes to the repository | | `git commit --amend --reset-author --no-edit` | Reset the author of your commit without editing the commit | | `git push` | Push changes to the remote repository | | `git pull` | Pull changes from the remote repository | | `git fetch` | Fetch changes from the remote repository | | `git merge <branch>` | Merge a branch into the current branch | | `git branch` | List all branches | | `git branch <branch>` | Create a new branch | | `git checkout <branch>` | Switch to a branch | | `git checkout -b <branch>` | Create and switch to a new branch | | `git branch -d <branch>` | Delete a branch | | `git log` | Show commit logs | | `git diff` | Show changes between commits | | `git blame <file>` | Show who changed each line in a file | | `git reflog` | Show a log of changes to HEAD | | `git reset --hard <commit>` | Reset the repository to a commit | | `git revert <commit>` | Revert a commit | | `git stash` | Stash changes in the working directory | | `git stash pop` | Apply stashed changes to the working directory | | `git tag <tag>` | Create a tag for a commit | | `git rm --cached <file>` | Unstage and remove files only from the index. | ## Configuration | Command | Description | | --- | --- | | `git config --global user.name <user>` | Set the user name for Git | | `git config --global user.email <email>` | Set the user email for Git | | `git config --global core.editor <editor>` | Set the default text editor for Git | | `git config --global color.ui auto` | Enable colored output for Git | ## Remote Repositories | Command | Description | | --- | --- | | `git remote add <repository> <url>` | Add a remote repository | | `git remote -v` | List remote repositories | | `git remote show <repository>` | Show information about a remote repository | | `git remote rename <repository> <new_repository>` | Rename a remote repository | | `git remote remove <repository>` | Remove a remote repository | ## Convert Directory to submodule - Install git-filter-repo package ```bash apt install git-filter-repo -y ``` - Clone fresh copy of main repo ```bash git clone [email protected]:username/repository.git submodule-repo cd submodule-repo ``` - Remove main repo origin ```bash git remote rm origin ``` - Perform repo filter ```bash git filter-repo --subdirectory-filter path/to/folder ``` - Add submodule repo origin ```bash git remote add origin https://github.com/user/submodule ``` - Push branch to submodule repo ```bash git push --set-upstream origin main ``` #### Use submodule in main repo - Remove folder that was converted to submodule ```bash rm -rf path/to/folder ``` - Add submodule ```bash git submodule add [email protected]:username/repository.git path/to/folder ``` Sources: [How to Turn a Turn a Directory in a Git Repository Into a Submodule](https://www.howtogeek.com/devops/how-to-turn-a-turn-a-directory-in-a-git-repository-into-a-submodule/) [Git Filter-Repo Submodule Extraction | by Bobby Galli | Level Up Coding](https://levelup.gitconnected.com/git-filter-repo-submodule-extraction-fb84de4c0ed6)