Skip to content

Advanced Git

Submodules

Create a new submodule within your repository:

git submodule add <repository_url> <path>

Clone a repository and initialize its submodules:

git clone --recursive <repository_url>

Update all the submodules in your repository to the latest commit of their respective branches:

git submodule update

Pull the latest changes from the remote repositories of the submodules and update them in your main repository:

git submodule update --remote

Remove a submodule from your repository:

git submodule deinit <path>
git rm <path>
git commit -m "Removed submodule"

Cherry-picking

Cherry-picking allows you to apply a specific commit from one branch to another branch.

git cherry-pick <commit_hash>

Reflog

Display the reflog, showing the history of HEAD and branch movements:

git reflog

Find the hash of the lost commit or branch using the reflog and then checkout to that hash to restore it:

git checkout <commit_or_branch_hash>

Comments