Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check out a specific version of a submodule using 'git submodule'?

People also ask

How do I update a specific submodule?

By adding the submodule. <name>. update config setting, you ensure that the selective clone of the submodule will be followed by an update, only for that submodule.

How do I pull up the latest submodule?

if you want to pull your submodules to latest commits instead of the current commit the repo points to. Probably you should use git submodule update --recursive nowadays. update will update each submodule to the specified revision, not update it to the latest for that repository.

What is git submodule update?

A git submodule update will bring the latest commits into your local Git worktree. In this git submodule update example, we'll show you how branches can seem out of sync between your submodule and the latest commit, and how to issue the appropriate git command to update those git submodules with the latest code.


Submodule repositories stay in a detached HEAD state pointing to a specific commit. Changing that commit simply involves checking out a different tag or commit then adding the change to the parent repository.

$ cd submodule
$ git checkout v2.0
Previous HEAD position was 5c1277e... bumped version to 2.0.5
HEAD is now at f0a0036... version 2.0

git-status on the parent repository will now report a dirty tree:

# On branch dev [...]
#
#   modified:   submodule (new commits)

Add the submodule directory and commit to store the new pointer.


Step 1: Add the submodule

   git submodule add git://some_repository.git some_repository

Step 2: Fix the submodule to a particular commit

By default the new submodule will be tracking HEAD of the master branch, but it will NOT be updated as you update your primary repository. In order to change the submodule to track a particular commit or different branch, change directory to the submodule folder and switch branches just like you would in a normal repository.

   git checkout -b some_branch origin/some_branch

Now the submodule is fixed on the development branch instead of HEAD of master.

From Two Guys Arguing — Tie Git Submodules to a Particular Commit or Branch .