How to pull a new submodule
Tried looking for answers on this site and others: StackOverflow question.
It seems like everyone wants to talk about whether you are in control of them, not if someone added it, and I just want to pull the additional project into my project without attaching or copying my changes if I need to delete the folder.
Should I delete the file .gitmodules
and / or submodule directories that I have already removed with git clone --recursive
? ( stack overflow )
These commands also don't help:
-
git submodule update --init --recursive
looks like it didn't do anything. -
git submodule update --recursive
nothing. -
git fetch --recurse-submodules
outputFetching submodule ...
multiple times. -
git pull --recurse-submodules
output the same thing, and then pronouncedAlready up-to-date.
after a trial sample. Strange as my submodules are already loaded anyway. -
git clone --recursive ...
Haven't tried it yet. I feel like I would rewrite any changes I have made in Stash or otherwise. -
git submodule update --recursive --remote
checked out the new SHA commit for one of the submodules. -
git submodule update --recursive
checked out the new SHA commit for one of the submodules. There may be an older, original fixation level. -
git submodule status
provides the relevant SHA, version and name information for each, but missing the one I want. -
git submodule foreach git pull origin master
-
git submodule update
doing nothing.
I checked the library directory manually each time to make sure an additional submodule appeared.
I want to avoid doing certain actions if they don't ruin my current state of the repository containing the code changes and solves my problem, if it's a command I mentioned but didn't run, or someone else has a try.
I could try some of them with a lot of effort, but I think I want to stop messing with them for now, and since I haven't found an answer to this question after some online searches, perhaps a hopeful and possible answer please help others in anyway.
Am I suffering from being mentioned here at all? Software development - Git subodule vs Git clone
Other links:
source to share
The best suggestion I've gotten so far is to execute this command:
git submodule add <URL_to_submodule> <local_path_to_place_submodule>
So this looks like what another contributor would do, which I will do again, even if it already exists in the remote.
I am guessing this is not technically updating the file .gitmodules
from the deleted data as expected, but haven't found a way to do it yet.
Credit for help goes to @pandatrax .
Update
Before trying the method add
, I tried another idea, which was to .gitmodules
manually copy the file from the remote and try any of the update commands, but unfortunately this approach didn't work either. It might have been different if I executed the commands in the root as I was in a sub folder, but I doubt it.
Then I used the method add
that downloaded the dependency but the file .gitmodules
showed the changes. After I installed the remote GitHub and pulled from it after dropping that file, the project is now in a better state, even syncing the SHS for the updated module or 2, either since they matched or were overwritten.
source to share
You need to do two things:
- Make
git pull
in your main repository which contains submodules. This will add a new submodule as an empty directory. - Make it
git submodule update --recursive --remote
in the main repository. This will bring the latest changes for all submodules, including the new one.
This works at least in Git 2.13. Also note that if the repos and submodules are on GitHub, you must ensure that you have permission to access them (if they are private).
source to share