Git Submodule: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
(Created page with "<source lang="bash"> /opt/chorke/academia ├─ master │ ├─ AcademiaApi │ ├─ AcademiaGui │ └─ AcademiaApp ├─ server │ ├─ ac...")
 
 
(28 intermediate revisions by the same user not shown)
Line 1: Line 1:
Git submodule is very simple where you have to aware about few things. Those are as following:
1. After addition of submodule, you have commit main module must
2. After pull of submodule, you have to pull/commit main module
3. After commit of submodule, you have to commit main module
==Structure==
<source lang="bash">
<source lang="bash">
/opt/chorke/academia
:'
  ├─ master
/opt/chorke/academia
  │  ├─ AcademiaApi
  ├─ master
  │  ├─ AcademiaGui
  │  ├─ AcademiaApi
  │  └─ AcademiaApp
  │  ├─ AcademiaGui
  ├─ server
  │  └─ AcademiaApp
  │  ├─ academia-init-rmsapi.git
  ├─ server
  │  ├─ academia-init-rmsapi.git
  │  ├─ academia-apps-ckiapi.git
  │  └─ academia-init-rmsapi.git
  │  ├─ academia-apps-ckigui.git
  └─ client
  │  └─ academia-apps-ckiapp.git
      ├─ AcademiaApi
  └─ client
      ├─ AcademiaGui
    ├─ AcademiaApi
      └─ AcademiaApp
    ├─ AcademiaGui
    └─ AcademiaApp
'
cd /opt/chorke/academia/server/
git init --bare academia-apps-ckiapi.git
git init --bare academia-apps-ckigui.git
git init --bare academia-apps-ckiapp.git
</source>


 
==Master==
# server side
<source lang="bash">
cd  /opt/chorke/academia/server/
:'
git init --bare academia-init-rmsapi.git
/opt/chorke/academia/master/AcademiaApi
git init --bare academia-init-rmsgui.git
git init --bare academia-init-rmsapp.git
 
 
# master/api
cd  /opt/chorke/academia/master/AcademiaApi
   ├─ .gitignore
   ├─ .gitignore
   ├─ LICENSE
   ├─ README.md
   └─ README.md
   └─ LICENSE
'
cd /opt/chorke/academia/master/AcademiaApi;git init
git remote add origin /opt/chorke/academia/server/academia-apps-ckiapi.git
git add --all; git commit -m 'initial commit'; git push origin master
</source>


 
<source lang="bash">
git init
:'
git remote add origin /opt/chorke/academia/server/academia-init-rmsapi.git
/opt/chorke/academia/master/AcademiaGui
git add --all;git commit -m 'initial commit'
 
 
# master/gui
cd  /opt/chorke/academia/master/AcademiaGui
   ├─ .gitignore
   ├─ .gitignore
   ├─ LICENSE
   ├─ README.md
   └─ README.md
   └─ LICENSE
'
cd /opt/chorke/academia/master/AcademiaGui;git init
git remote add origin /opt/chorke/academia/server/academia-apps-ckigui.git
git add --all; git commit -m 'initial commit'; git push origin master
</source>


git init
<source lang="bash">
git remote add origin /opt/chorke/academia/server/academia-init-rmsgui.git
:'
git add --all;git commit -m 'initial commit'
/opt/chorke/academia/master/AcademiaApp
 
 
# master/app
cd  /opt/chorke/academia/master/AcademiaApp
   ├─ .gitignore
   ├─ .gitignore
   ├─ LICENSE
   ├─ README.md
   └─ README.md
   └─ LICENSE
'
cd /opt/chorke/academia/master/AcademiaApp;git init
git remote add origin /opt/chorke/academia/server/academia-apps-ckiapp.git
git add --all; git commit -m 'initial commit'; git push origin master
</source>


git init
<source lang="bash" highlight="10,11,13,14">
git remote add origin /opt/chorke/academia/server/academia-init-rmsapp.git
:'
git add --all;git commit -m 'initial commit'
git submodule add /opt/chorke/academia/server/academia-apps-ckiapi.git
git submodule add /opt/chorke/academia/server/academia-apps-ckigui.git


git rm --cached academia-apps-ckiapi; git rm --cached academia-apps-ckigui
git rm --cached .gitmodules; git reset --hard; git clean -fd
rm -rf academia-apps-cki*
'


# master/sub
git submodule add /opt/chorke/academia/server/academia-apps-ckiapi.git AcademiaApi
git submodule add /opt/chorke/academia/server/academia-init-apigui.git
git submodule add /opt/chorke/academia/server/academia-apps-ckigui.git AcademiaGui
git submodule add /opt/chorke/academia/server/academia-init-rmsgui.git


git rm --cached .gitmodules
git config -f .gitmodules submodule.AcademiaApi.branch master
git rm --cached academia-init-rmsapi
git config -f .gitmodules submodule.AcademiaGui.branch master
git rm --cached academia-init-rmsgui


git clean -fd;git reset --hard
git commit -m 'academia-ruap-{ckiapi,ckigui} added'
rm -rf academia-init-rms*
 
 
git submodule add /opt/chorke/academia/server/academia-init-rmsapi.git AcademiaApi
git submodule add /opt/chorke/academia/server/academia-init-rmsgui.git AcademiaGui
git commit -m 'academia-ruap-{rmsapi,rmsgui} added'
git push origin master
git push origin master
</source>


==Client==
<source lang="bash" highlight="5">
# academia/client/AcademiaApp
cd /opt/chorke/academia/client/
git clone /opt/chorke/academia/server/academia-apps-ckiapp.git AcademiaApp
# cd AcademiaApp; git submodule init; git submodule update
cd AcademiaApp; git submodule update --init


# client/app
vim HelloApp.txt;git add HelloApp.txt
cd  /opt/chorke/academia/client/
git commit -m 'Hello App Added'
git clone /opt/chorke/academia/server/academia-init-rmsapp.git AcademiaApp
</source>
cd AcademiaApp/


===Wrong===
<source lang="bash" highlight="8-10">
# client/AcademiaApp/AcademiaGui
cd /opt/chorke/academia/client/AcademiaApp/AcademiaGui/
vim HelloGui.txt; git add HelloGui.txt
git commit -m 'Hello Gui Added'
git status; cd ..; git status


# client/sub
# academia/client/AcademiaApp
cd  /opt/chorke/academia/client/AcademiaApp/
git submodule init
git submodule update
 
 
# client/gui
cd  /opt/chorke/academia/client/AcademiaApp/AcademiaGui/
vim HelloGui.txt
cd ..
 
 
# client/app
vim HelloApp.txt
git add --all;git commit -m 'Hello App Added'
git status
 
 
# client/gui
cd AcademiaGui/
git add --all;git commit -m 'Hello Gui Added'
git status
cd ..
 
 
# client/app
git status
git submodule status --recursive
git submodule status --recursive
 
git submodule foreach git pull origin master
git submodule foreach git push -u origin master
git submodule foreach git push -u origin master
git submodule foreach git pull origin master


# master/gui
# academia/master/AcademiaGui
cd /opt/chorke/academia/master/AcademiaGui/
cd /opt/chorke/academia/master/AcademiaGui/
git pull origin master
git pull origin master
</source>
===Right===
<source lang="bash" highlight="3,8,22,27,28">
# client/AcademiaApp/AcademiaGui
cd /opt/chorke/academia/client/AcademiaApp/AcademiaGui/
git checkout master; vim HelloGui.txt; git add HelloGui.txt
git commit -m 'Hello GUI Added'
git push origin master; cd ..


# client/sub/gui
# academia/client/AcademiaApp
cd  /opt/chorke/academia/client/AcademiaApp/AcademiaGui/
git add AcademiaGui; git commit -m 'AcademiaGui updated'
git checkout master
vim HelloGui.txt
git add --all;git commit -m 'Hello GUI Added'
git push origin master
git push origin master
cd ..


# client/app
# academia/master/AcademiaGui
git add AcademiaGui
cd /opt/chorke/academia/master/AcademiaGui/
git commit -m 'AcademiaGui updated'
vim HelloAdd.txt; git add HelloAdd.txt
git commit -m 'Hello Add Text File Added'
git push origin master
git push origin master


git config -f .gitmodules submodule.AcademiaApi.branch master
# client/AcademiaApp/AcademiaGui
git config -f .gitmodules submodule.AcademiaGui.branch master
cd /opt/chorke/academia/client/AcademiaApp/AcademiaGui/
git pull origin master; cd ..


# master/gui
# academia/client/AcademiaApp
cd  /opt/chorke/academia/master/AcademiaGui/
git add AcademiaGui; git commit -m 'AcademiaGui updated'
vim HelloAdd.txt
git add HelloAdd.txt;git commit -m 'Hello Add Text File Added'
git push origin master
git push origin master


# client/sub/gui
# academia/master/AcademiaApp
cd /opt/chorke/academia/client/AcademiaApp/AcademiaGui/
cd /opt/chorke/academia/master/AcademiaApp/
git submodule foreach git pull origin master
git pull origin master
git pull origin master
cd ..
</source>


# client/app
==Rename==
git status
<source lang="bash" highlight="6,7,10">
git add AcademiaGui
git clone /opt/chorke/academia/server/agronomy-apps-ckiapp.git AgronomyApp
git commit -m 'AcademiaGui updated'
git clone /opt/chorke/academia/server/agronomy-apps-ckiapi.git AgronomyApi
git push origin master
git clone /opt/chorke/academia/server/agronomy-apps-ckigui.git AgronomyGui
 
cd AgronomyApp
git mv AcademiaApi AgronomyApi
git mv AcademiaGui AgronomyGui


# master/gui
# update modules
cd  /opt/chorke/academia/master/AcademiaApp/
vim .gitmodules
git submodule foreach git pull origin master
git pull origin master
</source>
</source>
==Knowledge==
git submodule init
git submodule update
git config --global init.defaultBranch master
==References==
* [https://stackoverflow.com/questions/17195861 Undo <code>git update-index --assume-unchanged</code>]
* [https://stackoverflow.com/questions/1777854 Specify a branch/tag when adding a Git submodule]
* [https://stackoverflow.com/questions/5542910 Commit changes in a git submodule]
* [https://cdn.chorke.org/goto/watch?v=CRlGDDprdOQ Git Merge vs Rbase] <code>YouTube</code>
* [https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_subtree_merge Git Tools Advanced Merging]
* [https://stackoverflow.com/questions/4526910/ Git Rename a Submodule]
* [https://git-scm.com/book/en/v2/Git-Tools-Submodules Git Tools Submodules]
* [[GitLab]]
* [[Git]]

Latest revision as of 01:54, 13 March 2023

Git submodule is very simple where you have to aware about few things. Those are as following:

1. After addition of submodule, you have commit main module must
2. After pull of submodule, you have to pull/commit main module
3. After commit of submodule, you have to commit main module

Structure

:'
/opt/chorke/academia
  ├─ master
  │  ├─ AcademiaApi
  │  ├─ AcademiaGui
  │  └─ AcademiaApp
  ├─ server
  │  ├─ academia-apps-ckiapi.git
  │  ├─ academia-apps-ckigui.git
  │  └─ academia-apps-ckiapp.git
  └─ client
     ├─ AcademiaApi
     ├─ AcademiaGui
     └─ AcademiaApp
'
cd /opt/chorke/academia/server/
git init --bare academia-apps-ckiapi.git
git init --bare academia-apps-ckigui.git
git init --bare academia-apps-ckiapp.git

Master

:'
/opt/chorke/academia/master/AcademiaApi
   ├─ .gitignore
   ├─ README.md
   └─ LICENSE
'
cd /opt/chorke/academia/master/AcademiaApi;git init
git remote add origin /opt/chorke/academia/server/academia-apps-ckiapi.git
git add --all; git commit -m 'initial commit'; git push origin master
:'
/opt/chorke/academia/master/AcademiaGui
   ├─ .gitignore
   ├─ README.md
   └─ LICENSE
'
cd /opt/chorke/academia/master/AcademiaGui;git init
git remote add origin /opt/chorke/academia/server/academia-apps-ckigui.git
git add --all; git commit -m 'initial commit'; git push origin master
:'
/opt/chorke/academia/master/AcademiaApp
   ├─ .gitignore
   ├─ README.md
   └─ LICENSE
'
cd /opt/chorke/academia/master/AcademiaApp;git init
git remote add origin /opt/chorke/academia/server/academia-apps-ckiapp.git
git add --all; git commit -m 'initial commit'; git push origin master
:'
git submodule add /opt/chorke/academia/server/academia-apps-ckiapi.git
git submodule add /opt/chorke/academia/server/academia-apps-ckigui.git

git rm --cached academia-apps-ckiapi; git rm --cached academia-apps-ckigui
git rm --cached .gitmodules; git reset --hard; git clean -fd
rm -rf academia-apps-cki*
'

git submodule add /opt/chorke/academia/server/academia-apps-ckiapi.git AcademiaApi
git submodule add /opt/chorke/academia/server/academia-apps-ckigui.git AcademiaGui

git config -f .gitmodules submodule.AcademiaApi.branch master
git config -f .gitmodules submodule.AcademiaGui.branch master

git commit -m 'academia-ruap-{ckiapi,ckigui} added'
git push origin master

Client

# academia/client/AcademiaApp
cd /opt/chorke/academia/client/
git clone /opt/chorke/academia/server/academia-apps-ckiapp.git AcademiaApp
# cd AcademiaApp; git submodule init; git submodule update
cd AcademiaApp; git submodule update --init

vim HelloApp.txt;git add HelloApp.txt
git commit -m 'Hello App Added'

Wrong

# client/AcademiaApp/AcademiaGui
cd /opt/chorke/academia/client/AcademiaApp/AcademiaGui/
vim HelloGui.txt; git add HelloGui.txt
git commit -m 'Hello Gui Added'
git status; cd ..; git status

# academia/client/AcademiaApp
git submodule status --recursive
git submodule foreach git pull origin master
git submodule foreach git push -u origin master

# academia/master/AcademiaGui
cd /opt/chorke/academia/master/AcademiaGui/
git pull origin master

Right

# client/AcademiaApp/AcademiaGui
cd /opt/chorke/academia/client/AcademiaApp/AcademiaGui/
git checkout master; vim HelloGui.txt; git add HelloGui.txt
git commit -m 'Hello GUI Added'
git push origin master; cd ..

# academia/client/AcademiaApp
git add AcademiaGui; git commit -m 'AcademiaGui updated'
git push origin master

# academia/master/AcademiaGui
cd /opt/chorke/academia/master/AcademiaGui/
vim HelloAdd.txt; git add HelloAdd.txt
git commit -m 'Hello Add Text File Added'
git push origin master

# client/AcademiaApp/AcademiaGui
cd /opt/chorke/academia/client/AcademiaApp/AcademiaGui/
git pull origin master; cd ..

# academia/client/AcademiaApp
git add AcademiaGui; git commit -m 'AcademiaGui updated'
git push origin master

# academia/master/AcademiaApp
cd /opt/chorke/academia/master/AcademiaApp/
git submodule foreach git pull origin master
git pull origin master

Rename

git clone /opt/chorke/academia/server/agronomy-apps-ckiapp.git AgronomyApp
git clone /opt/chorke/academia/server/agronomy-apps-ckiapi.git AgronomyApi
git clone /opt/chorke/academia/server/agronomy-apps-ckigui.git AgronomyGui

cd AgronomyApp
git mv AcademiaApi AgronomyApi
git mv AcademiaGui AgronomyGui

# update modules
vim .gitmodules

Knowledge

git submodule init
git submodule update
git config --global init.defaultBranch master

References