- Basic Commands Overview
| Command | Description |
|---|---|
git submodule add <repo_url> |
Add a submodule to your project |
git submodule init |
Initialize your submodules |
git submodule update |
Fetch and checkout submodule commits |
git submodule status |
Check the status of your submodules |
git submodule foreach <command> |
Run a command in each submodule |
git clone --recurse-submodules |
Clone a repository and its submodules |
git submodule sync |
Sync submodule URLs when they change |
git push |
Push changes in the main project and submodule (if updated) |
-
Add a Git Submodule
git submodule add <remote_url> <destination_folder> git commit -m "Added the submodule to the project." git push
-
Pull a Git Submodule
git submodule update --init --recursive
-
Update a Git Submodule
git submodule update --remote --merge
-
Fetch new submodule commits
$ cd <repository>/<submodule> $ git fetch $ git log --oneline origin/master -3 93360a2 (origin/master, origin/HEAD) Second commit 88db523 First commit 43d0813 (HEAD -> master) Initial commit $ git checkout -q 93360a2 $ cd <repository> $ git add . $ git commit -m "Added new commits from the submodule repository" $ git push
-
Remove Git submodules
$ git submodule deinit <submodule> $ git rm <submodule>
-
Add
git remote add origin <remote_url> git branch -M main git push -u origin main
-
Use
git remote add upstream <remote_url> git fetch upstream git rebase upstream/main git push origin
-
Check
git remote -v
-
Remove
git remote rm <remote_name>
sudo apt install git-lfs -y-
Initialize Git LFS in a repository
git lfs install
-
Track large files
git lfs track "*.psd" git add .gitattributes git commit -m "Track PSD files using Git LFS"
-
Adding large files to Git
git add large-file.psd git commit -m "Added large PSD file" -
Cloning a repository with Git LFS
git clone https://github.com/username/repo.git cd repo # Pull down all LFS files git lfs pull
-
Fetching and Pulling large files
git lfs fetch git pull
-
Checking status of LFS files
git push origin main
-
Untracking files
git lfs untrack "*.psd" -
Fetching Recent Files
git lfs fetch --recent git lfs fetch --recent <n> # Fetches LFS objects for commits made in the last n days. git lfs fetch --recent --recent-refs-days <n> git lfs fetch --recent --recent-commits-days 7 # fetches commits from the last 7 days # Fetch Specific LFS Files by Pattern (-I and -X) # -I Option (Include specific files): git lfs fetch -I "path/to/file.txt" git lfs fetch -I "*.jpg" # -X Option (Exclude specific files): git lfs fetch -X "*.png" # Combined Example (-I and -X): git lfs fetch -I "*.jpg" -X "*.large.jpg"