Tuesday, February 24, 2015

Git Submodule Tutorial


Requirement: Automation run needs code from framework repository which is maintained independently. How do we ensure that we also get framework code whenever we clone/update product automation code.

Solution: Make “framework” a submodule of “automation”

Framework: https://stashserver/stash/scm/abc/framework.git

Automation: https://stashserver/stash/scm/ta/automation.git

Task 1: Add submodule



 git clone -c http.sslVerify=false clone https://stashserver/stash/scm/ta/automation.git

 git submodule add https://stashserver/stash/scm/abc/framework.git

 git commit –m “Add submodule named framework”

 git push origin master

Task 2: Clone automation code repository which includes submodule



 git clone --recursive https://stashserver/stash/scm/ta/automation.git

Task 3: Get latest contents for automation project and framework submodule in an already cloned repository



 cd automation_project_dir

 git pull --recurse-submodules

 git submodule update

Task 4: Update the revision of framework repository which is being referred to by automation repositories



 cd automation_project_dir

 git submodule update --remote framework

 git add framework

 git push origin master

No comments: