Git reference - submodules

GIT Submodules:

To initially set up the submodules:

> pwd
<main repository>
> git submodule init
> git submodule update

Note: "git submodule update" tell that "hello submodules!! I have commit x as index for you. Please checkout to commit x"

> cd <submodule dir>
> git checkout master (or) what branch you want
> git pull
> cd <main repository>
> git status
> git add <sumodule dir>
>  git commit -m "update HEADLINK"

short and sweet for init and update:
mainrepositry > git submodule update --init --recursive

To fetch the latest commit from submodules:
> cd <submodule dir>
> git checkout <branch>
> git pull
> cd <main repository>
> git commit -m "pulling down latest changes from submodules"

short and sweet: 
mainrepository > git submodule foreach git pull origin master
if the submodules contain other submodules use:
mainrepository> git submodule foreach --recursive git pull origin master

Note: If you do "git submodule update" from main repository then git will checkout the submodule branch commit to the index specified in main repository. So, it is better directly go to the submodule directory and do the pull to fetch the latest changes.

Reference: http://stackoverflow.com/questions/5828324/update-git-submodule-to-latest-commit-on-origin

To summarize:
1) Initial setup:

mainrepositry > git submodule update --init --recursive
2) Pull latest changes from submodules

mainrepository> git submodule foreach --recursive git pull origin master

3) Check the status in main repository

mainrepository> git status
it may show like "new commits" if submodules files has new changes

4) Commit the changes, so that main repository points to the new changes in submodules
mainrepository> git commit -m "updating the submodules to latest version"

Note: There is a possibility that someone else committed the main repository with the latest changes from sub modules. So, in that case just use "main repository> git submodule update". How will I know whether submodules has changes?
Step1:
submoduledir> git show HEAD
it may show 1234 as SHA1
Step2:
mainrepository> git rev-parse HEAD:submduledir
it may show 2345 as SHA1. It means both are different. So, update the main repository for the latest changes from submodules.
Step3:
mainrepository> git submodule foreach --recursive git pull origin master
mainrepository> git commit -m "updating the submodules to latest version"
Step4:
In step2, if 1234 is shown ???











Comments

Popular posts from this blog

Programatically create layout builder section in Drupal

Code quality analysis of Drupal. Can I use Sonar?

Set up Drupal7 to Drupal8 migration in simple steps (using Drush)