82

I have a git submodule that I would like to become part of my main project (since I have a lot of project specific code that will go into the submodule).

So I'd like to remove the git references to the submodule and add the files to my main git repository.

But how ?

2
  • Just recursively remove .svn folders Commented Nov 5, 2014 at 8:22
  • This appears to be a duplicate of stackoverflow.com/questions/1759587/… Commented Apr 15, 2015 at 17:27

3 Answers 3

159

You must remove the gitlink entry in your index:

mv subfolder subfolder_tmp
git submodule deinit subfolder
git rm --cached subfolder
mv subfolder_tmp subfolder
git add subfolder

Replace subfolder with the name of the folder for your submodule, and make sure to not add any trailing slash.

This is what I detail in "Remove a Git submodule?" and "un-submodule a git submodule".

The --cached option allows you to keep the subfolder content in your disk... except git submodule deinit would already have removed that content anyway. Hence the mv part.

You then can add and commit that subfolder.

Sign up to request clarification or add additional context in comments.

7 Comments

But git submodule deinit subfolder removes the subfolder content from the disk. The --cached option does nothing since the content is already gone. (git 1.9.2)
@and-dev --cached removes from the index, not from the disk.
I found the deinit command put the subfolder back as an empty directory. The mv then put the temp subfolder into the new empty directory, rather than renaming it. So check the directories before doing the final mv. Otherwise, did the job.
just "git rm --cached subfolder" and "git add . " will help you
@TonyWang Add what though? As commented, the deinit command put the subfolder back as an empty directory.
|
28

First delete .git folder from the submodule.

Just running this removes the cached folder and contents from git but won't delete the folder.

git rm -r --cached [EnterFolderNameWithoutBrackets]

3 Comments

Should be the accepted answer. I would add also delete .gitmodules and edit .git/config to remove the entries to the submodules, although I am not sure that is necessary.
Why should this be the accepted answer @RafaelGuimaraesSiqueira? Why is this better than the currently accepted one?
@webejaxx It's because this one requires just one step and is easy to follow. The accepted answer does extra steps to eventually run the same command.
1

The answer from VonC will delete the submodule folder contents unless you rename the physical folder first - as shown in this answer, whose question was noted to be a duplicate by Chad:

https://stackoverflow.com/a/16162228

1 Comment

The accepted answer has been updated to reflect these concerns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.