I'm beginner to git & I have the following folder structure for new project, so what I did is I went to visual studio and I made empty project it has this folder structure:
project: (Repo)
folder1 (sub1)
folder2 (sub2)
I'm using git locally.
I created a repo for project using sourcetree,
now I cannot add any submodule, I don't know why.
In powershell whenever I try:
PS E:\Projects\Project> git submodule add ./sub1
I get the following error:
sub1 already exists in the index
then I decided to remove sub1 using git rm -r sub1
,and add it again, then when I tried to add it again using git submodule add
again, I received this new error:
sub1 already exists and is not a valid git repo
So what I'm doing wrong?
In the parent repo, you can also use git push --recurse-submodules=check which prevents pushing the parent repo if the submodule(s) are not pushed first. Another option is git push --recurse-submodules=on-demand which will try to push the submodules automatically (if necessary) before pushing the parent repo.
You can also change the commit that is checked out in each submodule by performing a checkout in the submodule repository and then committing the change in the parent repository. You add a submodule to a Git repository via the git submodule add command.
Add git submodule Next we will add a submodule to this fresh new repo. $ git submodule add https://bitbucket.org/jaredw/awesomelibrary Cloning into '/Users/atlassian/git-submodule-demo/awesomelibrary'... remote: Counting objects: 8, done. remote: Compressing objects: 100% (6/6), done.
You simply need to be in your root folder and then add the submodule folder.
git submodule add <url>
Now when you clone the project you simply need to init and update the submodule
git submodule init
git submodule update
Git 1.8.2 features a new option --remote
git submodule update --remote --merge
will fetch the latest changes from upstream in each submodule, merge them in, and check out the latest revision of the submodule. As [the docs][1] put it:
--remote
This option is only valid for the update command. Instead of using the superproject’s recorded SHA-1 to update the submodule, use the status of the submodule’s remote-tracking branch.
This is equivalent to running git pull in each submodule.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With