Skip to content

Instantly share code, notes, and snippets.

@OleksiyRudenko
Last active November 2, 2020 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OleksiyRudenko/268f460fe59ab9db673c2fadae6ff6e4 to your computer and use it in GitHub Desktop.
Save OleksiyRudenko/268f460fe59ab9db673c2fadae6ff6e4 to your computer and use it in GitHub Desktop.

WORK IN PROGRESS

Unintended submodule issue

One of the problems developers new to git may face is a mysterious sub-modules they didn't expect to have.

These are seen as a Submodule <pull request title> at <commit-hash> under Files changed tab in a pull request.

How this happens?

Option 1 - Unintentionally nested projects

You create your first repo following the instructions from some tutorial when in your $HOME directory by something like

mkdir programming
cd programming
git init

You learn and programming gets populated with files and directories. Eventually it becomes bound with a repo on GitHub and things goes quite well.

Next you create your second repo (by git init or git clone) and decide that programming directory is a good point to start at.

That's the problem. You have created a sub-module for your programming repository. You won't face any issues if you never introduce changes to programming but once you do you will an unintended sub-module (or a bunch of) in your programming repo.

How to fix

Just move your projects so that they all have a common parent directory and neither is nested inside any another.

Option 2 - Copied entire repo instead of project files only

One day yuo decide to make some of your projects a part of a new project. So, you initialize a new repo and copy (or move) some old repo into it as a subdirectory.

The old one brought its own .git sub-directory along. That's the problem. Any changes to the 'old' project directory won't be tracked from the new parent project and 'old' project will be treated as a sub-module.

How to fix

Assuming you have already added, commited and pushed a submodule.

  1. mv path/to/submodule path/to/submodule_tmp
  2. git submodule deinit path/to/submodule
  3. git rm path/to/submodule
  4. mv path/to/submodule_tmp path/to/submodule
  5. rm -rf path/to/submodule/.git

At this stage git status should expose files from your nested project available as they were just created.

Now you are ready to git add, git commit and git push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment