Skip to content
Fix Code Error

How do I remove a submodule?

March 13, 2021 by Code Error
Posted By: Anonymous

How do I remove a Git submodule?

By the way, is there a reason I can’t simply do
git submodule rm whatever ?

Solution

Since git1.8.3 (April 22d, 2013):

There was no Porcelain way to say “I no longer am interested in this submodule”, once you express your interest in a submodule with “submodule init“.
“submodule deinit” is the way to do so.

The deletion process also uses git rm (since git1.8.5 October 2013).

Summary

The 3-steps removal process would then be:

0. mv a/submodule a/submodule_tmp

1. git submodule deinit -f -- a/submodule    
2. rm -rf .git/modules/a/submodule
3. git rm -f a/submodule
# Note: a/submodule (no trailing slash)

# or, if you want to leave it in your working tree and have done step 0
3.   git rm --cached a/submodule
3bis mv a/submodule_tmp a/submodule

Explanation

rm -rf: This is mentioned in Daniel Schroeder‘s answer, and summarized by Eonil in the comments:

This leaves .git/modules/<path-to-submodule>/ unchanged.
So if you once delete a submodule with this method and re-add them again, it will not be possible because repository already been corrupted.


git rm: See commit 95c16418:

Currently using “git rm” on a submodule removes the submodule’s work tree from that of the superproject and the gitlink from the index.
But the submodule’s section in .gitmodules is left untouched, which is a leftover of the now removed submodule and might irritate users (as opposed to the setting in .git/config, this must stay as a reminder that the user showed interest in this submodule so it will be repopulated later when an older commit is checked out).

Let “git rm” help the user by not only removing the submodule from the work tree but by also removing the “submodule.<submodule name>” section from the .gitmodules file and stage both.


git submodule deinit: It stems from this patch:

With “git submodule init” the user is able to tell git they care about one or more submodules and wants to have it populated on the next call to “git submodule update“.
But currently there is no easy way they can tell git they do not care about a submodule anymore and wants to get rid of the local work tree (unless the user knows a lot about submodule internals and removes the “submodule.$name.url” setting from .git/config together with the work tree himself).

Help those users by providing a ‘deinit‘ command.
This removes the whole submodule.<name> section from .git/config either for the given
submodule(s)
(or for all those which have been initialized if ‘.‘ is given).
Fail if the current work tree contains modifications unless forced.
Complain when for a submodule given on the command line the url setting can’t be found in .git/config, but nonetheless don’t fail.

This takes care if the (de)initialization steps (.git/config and .git/modules/✘✘✘)

Since git1.8.5, the git rm takes also care of the:

  • ‘add‘ step which records the url of a submodule in the .gitmodules file: it is need to removed for you.
  • the submodule special entry (as illustrated by this question): the git rm removes it from the index:
    git rm --cached path_to_submodule (no trailing slash)
    That will remove that directory stored in the index with a special mode “160000”, marking it as a submodule root directory.

If you forget that last step, and try to add what was a submodule as a regular directory, you would get error message like:

git add mysubmodule/file.txt 
Path 'mysubmodule/file.txt' is in submodule 'mysubmodule'

Note: since Git 2.17 (Q2 2018), git submodule deinit is no longer a shell script.
It is a call to a C function.

See commit 2e61273, commit 1342476 (14 Jan 2018) by Prathamesh Chavan (pratham-pc).
(Merged by Junio C Hamano — gitster — in commit ead8dbe, 13 Feb 2018)

git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit 
  ${GIT_QUIET:+--quiet} 
  ${prefix:+--prefix "$prefix"} 
  ${force:+--force} 
  ${deinit_all:+--all} "[email protected]"
Answered By: Anonymous

Related Articles

  • Git submodule update
  • Git submodule head 'reference is not a tree' error
  • Error message "Forbidden You don't have permission…
  • Gradle error: Execution failed for task…
  • Update Git submodule to latest commit on origin
  • How to track untracked content?
  • ternary operator usage within v-bind class
  • Vue js vuecli3 application does not work in ie11…
  • Output not incrementing correctly - C++
  • Error: request entity too large
  • org.gradle.api.tasks.TaskExecutionException:…
  • Aurelia UX showcase app fails to load
  • Express JS: TypeError [ERR_INVALID_ARG_TYPE]: The…
  • C# Net.Core Object.Equals() returning false even if…
  • Combine Date and Time columns using python pandas
  • git: How to ignore all present untracked files?
  • Backbone.js rendering a reset collection with a single view
  • Express Session not persisting after CORS calls
  • How can I specify a branch/tag when adding a Git submodule?
  • No submodule mapping found in .gitmodule for a path…
  • ExpressJS How to structure an application?
  • Using JsonConvert.DeserializeObject to deserialize…
  • No Spring WebApplicationInitializer types detected…
  • Eclipse will not start and I haven't changed anything
  • Error: Can't set headers after they are sent to the client
  • How to enable cross-origin resource sharing (CORS)…
  • TempData keep() vs peek()
  • Why do I have to "git push --set-upstream origin "?
  • Setting scale_x_discrete limits removes both…
  • Problems Installing CRA & NextJS from NPM…
  • why req.body is empty and req.files undefined
  • git pull while not in a git directory
  • Can't upload files with Apollo-client GraphQL in…
  • Pandas groupby month and year
  • Checkout another branch when there are uncommitted…
  • Push git commits & tags simultaneously
  • Throw HttpResponseException or return…
  • Casting to number from query fails. Node.js Express Mongoose
  • Git Using Remote Branch
  • NodeJS: How to get the server's port?
  • Error: Failed to lookup view in Express
  • How to set up webpack-hot-middleware in an express app?
  • Generating swagger for Dictionary
  • Git - Pushing code to two remotes
  • Smart way to truncate long strings
  • node.js TypeError: path must be absolute or specify…
  • Dynamically update values of a chartjs chart
  • Difference between git checkout --track…
  • TypeError: Cannot read property 'webpackJsonp' of undefined
  • How to convert dataframe into time series?
  • Converting HTML Entities from JSON to String
  • React and Express iTunes Search API :: Error:…
  • How to structure a Node, Express, Connect-Auth and…
  • sort array of date-months in ascending order of type string
  • How to access POST form fields
  • When to use LinkedList over ArrayList in Java?
  • What is the difference between Visual Studio Express…
  • How to reverse $unwind or re-assemble after $lookup?
  • How do I make a Git commit in the past?
  • Including a standalone component in vue ant design steps
  • How do I consume the JSON POST data in an Express…
  • Uploading a file with express-fileupload doesn't work
  • How to convert a string to JSON object in PHP
  • Correctly configure webpack-dev-middleware with…
  • High Quality Image Scaling Library
  • Update a submodule to the latest commit
  • Node.js Error: Cannot find module express
  • Why do git fetch origin and git fetch : behave differently?
  • GROUP BY + CASE statement
  • Retrieve specific commit from a remote Git repository
  • List submodules in a Git repository
  • Use of String.Format in JavaScript?
  • TypeError: Router.use() requires middleware function…
  • Summarise the posterior of a single parameter from…
  • i am using nodejs and express to build a very simple…
  • Add missing dates to pandas dataframe
  • Can I "include" or exec a TypeScript file in a Jest test?
  • Next.js with or without express
  • How to access the request body when POSTing using…
  • Express.js - app.listen vs server.listen
  • Issues with registering Vuex modules, either…
  • Various ways to remove local Git changes
  • How do I use namespaces with TypeScript external modules?
  • How to retrieve a single file from a specific…
  • Normalize embedded records with ember-data
  • How do I clone a single branch in Git?
  • Express JS (Node): adding the prefix to routes is…
  • How do I "commit" changes in a git submodule?
  • What is "git remote add ..." and "git push origin master"?
  • How to solve Internal Server Error in Next.Js?
  • How to build next.js production?
  • How do I include a JavaScript file in another…
  • Authentication and cross domain error from a Node -…
  • How to run Next Js application build (out) directory?
  • Nuxt/ Vue bug for calling server multiple times on a…
  • Install Visual Studio 2013 on Windows 7
  • Using JSON object in Underscore template - Backbone.js
  • Saving data to a file in C#
  • what is the size of an enum type data in C++?
  • Node.js express POST 404ing

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Angular: conditional class with *ngClass

Next Post:

Use different Python version with virtualenv

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error