I am in the process of porting my JS application to modern E6 modules. My application is stored in a git repo. Within the repo there's a submodule.
I created another branch to do what I need to do, but I would like to remove the submodule in this specific branch.
The reason is that I have to npm install
the app within the submodule as a package rather than using it in "the classical submodule" way as I do in master branch.
Reading this answer I thought that would be as simple as checkout to the new branch, modify the .gitmodules file excluding the submodule and deleting the submodule folder itself.
However, when I do this, I checkout to master and it seems the submodule is missing from there as well, and this would be a tremendous error. I didn't stage the changes before checking out if this is important.
So, how do I get rid of the submodule in the new branch to start working in it, without loosing it in my master branch?
EDIT 1
I am trying again after phd comments. I am in the branch where I need to remove the gitmodule. I edited the .gitmodules
file to remove the submodule i need to remove, and then tried to remove the submodule with git rm -r <my_submodule>
but I get fatal: Please, stage your changes to .gitmodules or stash them to proceed
message.
So I stashed my changes and removed the submodule. Then I was able to checkout to the master branch, and the submodule folder was there (as I needed).
Also, the master .gitmodules
still showed the submodule I removed from the other branch, which was my aim.
So now I have a master branch with the submodule, and the "dev" branch without it and I can install with npm here. So I guess I messed up something and the asnwer I linked was right. Will accept phd answer as it was correct.
Finally, as I have git version 2.7.4 and I cannot run git checkout --recurse-submodules master
, I added this GIT PPA (I am using Ubuntu) as the version in the OS package manager was older, upgraded git to 2.19, run the command and everything worked just fine.
The command I used are:
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
apt-get install --only-upgrade git
EDIT 2
Strangely, I just noticed when I switch to the "dev" branch that the folder of the submodule I removed is still there, although the .gitmodules is not showing the submodule in the list. Also, during checkout to this branch I received the message warning: unable to rmdir 'ol/ol-layerswitcher': Directory not empty
.
I guess that now this folder is not treated as a submodule anymore, but it is still there. How could I get rid of it from the dev branch and not from the master branch (which was my original question) if it is possible?
FINAL ANSWER
Ok answered myself. I just needed to remove the floder without git rm
. Now the:
- the dev branch has nothing to commit
- the submodule folder is not there
- when I switch to it, I don't receive any message
FINAL ANSWER NOT TRUE!
Just wanted to add that deleting the files made them disappear also in the master branch. The only thing I could do apparently is living with the submodules folder in the devb ranch but just "ignoring" them with the .gitignore
in order not to push them to my remote dev branch.