U made some changes to the local repo and comitted them from which u got the submodule. How is git able to figure out that there are changes in the local repo when it is pointing to the remote url and not the local repo from which we got the submodule?
Good question, if you remember we have a ".gitmodules" that has a path to the submodule. This is telling git where to track the local changes. This is how it knows there are changes in the local repo. Hope that makes sense.
Your video really simplified this process for me! One question though: In other videos & articles, I've seen people say that, in order to incorporate changes from the submodule's repo, you have to run `git submodule update --remote` in the superproject repo before adding/committing/pushing. It looks like you didn't do that here, but everything worked fine. Do you know if `git submodule update --remote` is necessary?
Glad it helped. The reason I did not need that command here is because I updated the submodule directly from within the parent project. So there were no other changes in the remote. If for example a colleague had updated the submodule else where, my local copy would not know about that, so I would need to ensure it is updated before developing. One way to do it is with the command `git submodule update --remote`, the other would be to `cd` into the submodule repo, checkout master and just do a git pull. Hopefully that makes sense?
For me it was a little bit confusing, that the name of the "normal repository" contains the word submodule and the submodule itself didn't. I had to wrap my head around this couple of times but could have been just me. Other then that: Great explanation!
Hi, I am not able to see the submodule files i guess now i got the answer why.....thanks for that..but what if i want to undo and make it invisible again? also how can i add a version tag to the submodules and how can i use a feature branch of repo A as a submodule inside repo B so i can run a github action on B
You're welcome. I wonder if the "deinit" command is what you are looking for here? Tags would be added the same as any other repo. In terms of feature branch you can specify the branch in the .gitmodules file. Hopefully that helps!
howcome everytime i run submodules update, i go look at my submodule and it checksout the commit (now outdated) that i originally made the project with....thought update would fetch the latest commit for me. So im finding to stay up to date I have to go checkout main from my submodule. How to I make my submodule always update to main not the commit i started my repo with
I believe submodule update will only update according to the local remote. Have you tried adding the --remote flag? That should actually fetch and update for you (making the submodule is on the main branch too).
Thanks for the explanation. Simple and I can easily understand. But how to remove submodule completely from main repository? For example, remove youtube-tutorial submodule from git-submodule-tutorial repository?
Detailed explanation to get started with submodules. You could also use the "git submodule update --remote" to update the submodules if the changes were made by another member of your team(Not locally).
Thanks for the explanation 👍 One clarification needed... I own a repo called repo1 and it has a submodule called repo2. The repo2 has two files namely a.txt and b.txt . I want to create a new file c.txt in repo1 . I want to make sure the c.txt file should have the content of a.txt which is available under repo2 through submodule. How could I achieve this ? Any changes to a.txt in repo2 (in actual repo) also should reflect in my c.txt Hope I m not confusing... 😀
Anytime :) This depends on the tech used of course and exactly what you are trying to achieve. In general, if you need c.txt to contain content from the submodule, you could add a simple script that copies that content over. Then just run this script anytime you update the submodule. (or even a script that does both). Hope that helps, but if you are looking for something more specific let me know.
This was so helpful! I do have a question though... I made a change in my submodule repo but the change never showed up in my parent repo. Is there where I need to explicitly ask git to go update to the latest commit in that submodule?
Thank you! Thats right (assuming you have committed and pushed the changes in the submodule). I usually "cd" in to the submodule from the parent repo and git pull from there, but you can also use the submodule commands from the parent directory and that should do the trick. 👍🏽
@@RedhwanNacef Thank you so much for responding! A little bit after I asked, I ended up figuring out how to pull in those changes and then push/commit those changes to the submodule as a part of the parent repo. You said it very clearly here too, to track exactly what I was doing! Thanks again! :)
I’m not a git guru but to sum up - git submodule is a fancy name for submodules, they’re essentially just git projects - any commands u can use with your own git project can be used inside the modele projects(git push pull etc) - to recursively install submodules -recursive-submodules is necessary with git pull or clone - same thing goes for the git push as well
Hi Nice explanation!!! I have one query, if we initialize a sub-module so for which branch of sub-module project it is considered in the parent project?
Thanks! You can specify the submodule branch in the .gitmodules directory, if not it defaults to the remote HEAD (which basically means it defaults to the default branch). Hope that helps!
9:36 - Showing the branch in the command line prefix is very clever. How do you do that? Is that automatic? I am under anaconda, so I get to see the environment name, not the git branch name. Cheers,
Can you specify a submodule to reference a branch rather than a commit hash? The idea is to work on that submodule branch, ie new commits, push, pull/fetch, rebase. Then merge the submodule branch into, say, master. Can you specify a tag for the submodule?
I don't think you can, it will always reference a commit, however, you can specify a commit hash from a different branch. For example, you can specify a branch in the .gitmodules file and it will use the latest commit hash from the branch. You can still do the workflow you have specified, you will just need to make sure you use the right commit hash once merged. I don't you can specify a tag either, but again a tag will always be linked to a commit hash so I think you could use that commit. Hope that helps!
Great video. Question for you. I have a git repo that I need to break into different repos with submodules. Do you know of a way to do that and keep the git history for each new repo?
Thanks. Not sure if there is an easy way to do that, I remember hearing about a project where this was done but it was all manual with cherry picking etc. There may be some tools out there that might help with this. Good luck!
I think you helped me with a huge problem, I am trying to use strapi for my back-end and I have struggled getting it to commit in one repo I do believe this will be the fix! TY!
I just want to leave feedback here. I find your way of giving a material to be of very high quality. Compared to many others on learning platforms, you can give material fast and keep the essential pieces. Like, you only cover the most vital submodule commands. Really appreciate the way you teach. Saw this video and subscribed for more.
Great Video!! 👍👍 What if I'm cloning a third party tool that I'm not going to be making commits to, or very small changes at most? Can I just pull the commits to that repo?
@@RedhwanNacef I was thinking about receiving any changes they make in their repo. I may not make any changes to that third party tool myself. Forvige me, I'm still a noob 🙈
Good explanation. Last time I had to share a unit of in-house code between two projects I went with the internal NPM package, which was a bit of a nightmare to set up, deal with special keys etc etc. This would have been cleaner.
Thank you from a fellow scot, i am messing about with robot programming and need to share python and nodejs code between the code running on the robot and the code running on the desktop this gave me the overview i needed to realise that submodules were the elegant solution i needed. So many other options i have tried just gave me a major headache.
@@RedhwanNacef thank you. :) right now, I can't, but I will write you in a few days, what is happening. I can just say now that I cloned a HUGO theme into my repo according to the quick start instructions, then edited the theme and wanted to push the changes.
You should just be able to remove the .gitmodules file and all the submodule files and commit. (There may be some references in the .git directory to the submodule that you need to remove too) maybe try this: git.wiki.kernel.org/index.php/GitSubmoduleTutorial#Removal.
Simple and precise explanations, incredibly helpful. Thank you so much!
Thanks! Glad you enjoyed it 😊
I was looking for an answer regarding the cloning of submodules and you covered it in an incredibly clear way ! Thanks for that, great video!
You're very welcome, glad it helped! Thank you for the feedback.
0.75 Playback speed + focus helps.
👍🏽
command summary
git submodule add {child-repo-url}
# add submodules (this will create .gitmodules)
git pull --recurse-submodules
# bring submodule's files
git config submodule.recurse true
# always --recurse-submodules
git clone {parent-repo-url}
# clone your parent repo which have submodules
git submodule update --init
# bring submodule files to this repo
Thanks for the summary!
U made some changes to the local repo and comitted them from which u got the submodule. How is git able to figure out that there are changes in the local repo when it is pointing to the remote url and not the local repo from which we got the submodule?
Good question, if you remember we have a ".gitmodules" that has a path to the submodule. This is telling git where to track the local changes. This is how it knows there are changes in the local repo. Hope that makes sense.
Your video really simplified this process for me! One question though:
In other videos & articles, I've seen people say that, in order to incorporate changes from the submodule's repo, you have to run `git submodule update --remote` in the superproject repo before adding/committing/pushing. It looks like you didn't do that here, but everything worked fine.
Do you know if `git submodule update --remote` is necessary?
Glad it helped.
The reason I did not need that command here is because I updated the submodule directly from within the parent project. So there were no other changes in the remote. If for example a colleague had updated the submodule else where, my local copy would not know about that, so I would need to ensure it is updated before developing. One way to do it is with the command `git submodule update --remote`, the other would be to `cd` into the submodule repo, checkout master and just do a git pull. Hopefully that makes sense?
For me it was a little bit confusing, that the name of the "normal repository" contains the word submodule and the submodule itself didn't. I had to wrap my head around this couple of times but could have been just me.
Other then that: Great explanation!
git submodule init ; git submodule update ; git submodule foreach --recursive git checkout master
You got it 👌🏼
Hi,
I am not able to see the submodule files i guess now i got the answer why.....thanks for that..but what if i want to undo and make it invisible again?
also how can i add a version tag to the submodules and how can i use a feature branch of repo A as a submodule inside repo B so i can run a github action on B
You're welcome. I wonder if the "deinit" command is what you are looking for here? Tags would be added the same as any other repo. In terms of feature branch you can specify the branch in the .gitmodules file. Hopefully that helps!
I don't see why you used "youtube tutorial" repo as an example. Quite a helpful video nevertheless thankyou.
The repo doesn't really matter in this case, just the concept. Thanks!
Nice video 👍 I need to share config files between two Ansible repositories and git submodule with config files looks like a solution.
Redhwan: "This will take a few seconds"
Boost: "Go grab a coffee"
😂
thank you for Video.
question: how you can show the options in command line like in min : 14:02 ?
Anytime. I use zsh with the git plugin: github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git. which gives me that functionality :)
This is helpful, thanks
You really look like Ayrton Senna (as the RUclips Algorithm suggests)
Thanks I guess 😅
howcome everytime i run submodules update, i go look at my submodule and it checksout the commit (now outdated) that i originally made the project with....thought update would fetch the latest commit for me. So im finding to stay up to date I have to go checkout main from my submodule. How to I make my submodule always update to main not the commit i started my repo with
I believe submodule update will only update according to the local remote. Have you tried adding the --remote flag? That should actually fetch and update for you (making the submodule is on the main branch too).
Is there a way to do this with branches in the same repository instead of two different repositories ?
Not sure, I have never thought to do that. You could always try add the path/url and see if it works?
Thanks for the explanation. Simple and I can easily understand.
But how to remove submodule completely from main repository? For example, remove youtube-tutorial submodule from git-submodule-tutorial repository?
Thank you
You’re welcome
Detailed explanation to get started with submodules.
You could also use the "git submodule update --remote" to update the submodules if the changes were made by another member of your team(Not locally).
Biggest question mark I was left with, thanks for answering!
Thanks for the additional information.
Great tutorial, concise and great explanation. Thanks for showing all the other tutorials name in this video. Earned a sub 👍
Thanks for the feedback and the sub. 🙂
Very good video, very helpful, tks
Thanks
great explanation, thanks
Thank you.
Detailed and simple, incredibly helpful. Thanks!
9:00 if you have cloned your git repo but need to install the submodule, the command is "git submodule update --init"
Thank you for the tutorial. I have a question, what about private submodule repo?
can you make submodules out of specific folders in a repository?
but if we have more than one submodule and we want to downoloaded only a specific submodule into the main repo ?
This was great! Nice explanation. Now I can start using git submodules.
Thanks, glad it helped! 🙂
This was really helpful .Than you
Glad to hear that, thanks.
Thank you for the video tutorial, it helps me a lot! keep up
Glad it helped!
Thanks for the explanation 👍
One clarification needed...
I own a repo called repo1 and it has a submodule called repo2. The repo2 has two files namely a.txt and b.txt . I want to create a new file c.txt in repo1 . I want to make sure the c.txt file should have the content of a.txt which is available under repo2 through submodule. How could I achieve this ? Any changes to a.txt in repo2 (in actual repo) also should reflect in my c.txt
Hope I m not confusing... 😀
Anytime :) This depends on the tech used of course and exactly what you are trying to achieve. In general, if you need c.txt to contain content from the submodule, you could add a simple script that copies that content over. Then just run this script anytime you update the submodule. (or even a script that does both). Hope that helps, but if you are looking for something more specific let me know.
@@RedhwanNacef thanks mate 👍... that clarifies my doubt
This was so helpful! I do have a question though... I made a change in my submodule repo but the change never showed up in my parent repo. Is there where I need to explicitly ask git to go update to the latest commit in that submodule?
Thank you! Thats right (assuming you have committed and pushed the changes in the submodule). I usually "cd" in to the submodule from the parent repo and git pull from there, but you can also use the submodule commands from the parent directory and that should do the trick. 👍🏽
@@RedhwanNacef Thank you so much for responding! A little bit after I asked, I ended up figuring out how to pull in those changes and then push/commit those changes to the submodule as a part of the parent repo. You said it very clearly here too, to track exactly what I was doing! Thanks again! :)
Anytime 😊
I’m not a git guru but to sum up
- git submodule is a fancy name for submodules, they’re essentially just git projects
- any commands u can use with your own git project can be used inside the modele projects(git push pull etc)
- to recursively install submodules -recursive-submodules is necessary with git pull or clone
- same thing goes for the git push as well
You got it! The .gitmodules file is probably a good thing to remember too when summing up.
Very nice, thank you
Thanks and you're welcome 😊
Thank you this was wery helpful
This is a precious video, thanks for clarifying this subject !
Hi Nice explanation!!! I have one query, if we initialize a sub-module so for which branch of sub-module project it is considered in the parent project?
Thanks! You can specify the submodule branch in the .gitmodules directory, if not it defaults to the remote HEAD (which basically means it defaults to the default branch). Hope that helps!
9:36 - Showing the branch in the command line prefix is very clever. How do you do that? Is that automatic? I am under anaconda, so I get to see the environment name, not the git branch name. Cheers,
I am using a shell called 'Zsh' with 'Oh My Zsh' will lets you configure/customise all of this. It's very useful.
Can you specify a submodule to reference a branch rather than a commit hash?
The idea is to work on that submodule branch, ie new commits, push, pull/fetch, rebase. Then merge the submodule branch into, say, master.
Can you specify a tag for the submodule?
I don't think you can, it will always reference a commit, however, you can specify a commit hash from a different branch. For example, you can specify a branch in the .gitmodules file and it will use the latest commit hash from the branch. You can still do the workflow you have specified, you will just need to make sure you use the right commit hash once merged. I don't you can specify a tag either, but again a tag will always be linked to a commit hash so I think you could use that commit. Hope that helps!
Should I create a seperate repo for submodule?
Great video. Question for you. I have a git repo that I need to break into different repos with submodules. Do you know of a way to do that and keep the git history for each new repo?
Thanks. Not sure if there is an easy way to do that, I remember hearing about a project where this was done but it was all manual with cherry picking etc. There may be some tools out there that might help with this. Good luck!
Awesome tutorial
Thanks!
Nice explanation.
Thanks
Neato! Amazing explanation, thanks a lot. Greetings from Colombia. Keep it up!
Hello Colombia! Glad you enjoyed it 😊
Very well done, awesome tutorial, clean and precise :)
Thanks a lot!
You know the desciprition of the video could really use a short summary of the commands, so that i dont have to look for them. Great video thou!
Thanks for the feedback!
nice info brother
Thanks!
Amazing, thank you!
Thanks, man!
No problem!
Thank you very much for making this video ☺️
Thank you very much for watching 😊
Great, thanks man.
Great video
Thanks
This was a very nice beginner's look at submodules. Thank you.
Glad it was helpful!
Thanks for the video, it explains the matter clearly.
Glad it was helpful!
looks like pure man's package manager :)
kidding, of cause, i can see a couple of usecases... but still :)
Haha, very similar yes!
Really good explanation! Great video, thanks for it!
Thanks, glad it was helpful!
Brilliant explanation. Thank you so much!
Thanks! 🙂
Thanks for the video! It helped me solved a issue that I was struggling for a whole day
Glad it helped!
I think you helped me with a huge problem, I am trying to use strapi for my back-end and I have struggled getting it to commit in one repo I do believe this will be the fix! TY!
Can i update multiple destination repositories with one source repository while executing some git submodules command at the source repository ?
"git submodule update --remote" might be what you are looking for?
Clean and usefull explanations. Thank you!!!.
Glad you liked it!
13:00 it is not the same commit hash when you click to the youtube-tutorials submodule.
Excellent tutorial. Answered all my questions and more.
Thanks, glad it helped.
this was lit, ty sm
Glad you liked it
Had to use this for work. Thanks for the video!
Glad it helped!
Is your 'tree' command an alias?
If yes, could you share the entire command for the alias?
It is an alias for the tool 'exa' (an 'ls' replacement). The command I run is 'exa -T -L 2 --icons'.
I just want to leave feedback here. I find your way of giving a material to be of very high quality. Compared to many others on learning platforms, you can give material fast and keep the essential pieces. Like, you only cover the most vital submodule commands. Really appreciate the way you teach. Saw this video and subscribed for more.
Also this is amazing for managing typescript between projects (I think, gonna try now) Thank you so much!
Hope it goes well! Anytime 🙂
Thank's you man 🤝, very useful
You're welcome 👍
Great video
I enjoyed the content! It helped me a lot with a project I'm working on with some colleagues.
Very nice!
Thank you so much, excellent tutorial
You're very welcome, glad you liked it.
Great Video!! 👍👍 What if I'm cloning a third party tool that I'm not going to be making commits to, or very small changes at most? Can I just pull the commits to that repo?
Thank you! Yea the same approach can used with any repository as long as it is publicly accessible. Not sure if you have a specific use case in mind?
@@RedhwanNacef I was thinking about receiving any changes they make in their repo. I may not make any changes to that third party tool myself. Forvige me, I'm still a noob 🙈
Yea that makes sense. Git submodules should work fine for that. No worries, you will be a pro in no time!
clean and clear
that was great thanks
You’re welcome 😊
best tutorial for submodule concept
Glad you liked it, thanks!
clearly explained, thank you
You're welcome
Clear and concise. Good presentation style and technique.
Very good tutorial, thanks.
Thank you and you’re welcome 😊
Good explanation, thank you.
Glad it was helpful!
Great explanation
Good explanation. Last time I had to share a unit of in-house code between two projects I went with the internal NPM package, which was a bit of a nightmare to set up, deal with special keys etc etc. This would have been cleaner.
Thanks! Yea I have done the exact same thing before, always good to better understand the alternatives. 🙂
Thanks for the explanation.
You're welcome!
Excellent explanation. Thanks.
Glad it was helpful!
Thank you from a fellow scot, i am messing about with robot programming and need to share python and nodejs code between the code running on the robot and the code running on the desktop this gave me the overview i needed to realise that submodules were the elegant solution i needed. So many other options i have tried just gave me a major headache.
Thanks for your time, totally helpful!
Very useful and well explained. Thanks
great video. Thanks!
Glad you liked it! Thanks 😊
This guy rocks. Thank you!
Cheers!
Thanks ❤
Well presented, clear, and informative! Great job! Thank you. :)
I tried everything, but it doesn't work for the HUGO theme which I tried to adjust.
Sorry I don't understand the issue. If you can try explain the issue/point to me a repo I am happy to try take a look and help.
@@RedhwanNacef thank you. :) right now, I can't, but I will write you in a few days, what is happening. I can just say now that I cloned a HUGO theme into my repo according to the quick start instructions, then edited the theme and wanted to push the changes.
❤🔥
👌🏼
Nice! Thank you for the content
Thanks, my pleasure!
how do I delete a submodule created by accident??
You should just be able to remove the .gitmodules file and all the submodule files and commit. (There may be some references in the .git directory to the submodule that you need to remove too) maybe try this: git.wiki.kernel.org/index.php/GitSubmoduleTutorial#Removal.
i am unable to access components from submodule
Any error message/repo you can share so I can try help?
Very simple and clear, thanks man!
wow simple and yet all i needed
Thank you 😊
Bit slow pls... Not everyone can understand your slang and phase of voice
I'll try!
@@RedhwanNacef thanks lot