If you previously used a Git submodule to pull in third-party code and now want to manage that directory as a regular part of your repository, you need to fully remove the submodule first. Simply deleting the folder or running `git add` on it will not work because Git still has submodule metadata referencing that path.

## Remove the submodule reference from the index

Start by telling Git to stop tracking the submodule:

```bash
$ git rm --cached path/to/submodule
rm 'path/to/submodule'
```

This removes the submodule entry from Git's index but leaves the files on disk.

## Remove the submodule from .gitmodules

Open `.gitmodules` and delete the section for your submodule:

```ini
[submodule "path/to/submodule"]
    path = path/to/submodule
    url = https://github.com/example/library.git
```

Remove the entire block, then stage the change:

```bash
$ git add .gitmodules
```

If this was the only submodule, you can remove the `.gitmodules` file entirely.

## Remove the submodule from .git/config

Open `.git/config` and delete the matching section:

```ini
[submodule "path/to/submodule"]
    url = https://github.com/example/library.git
```

## Clean up the submodule directory

Git keeps internal submodule data in `.git/modules/`. Remove it:

```bash
$ rm -rf .git/modules/path/to/submodule
```

If the actual submodule directory is still on disk from the earlier step, make sure it contains the files you want to keep. If it is empty or stale, delete and re-create it with the files you need.

## Add your files to the repository

Now Git no longer thinks that path is a submodule. You can add files there normally:

```bash
$ git add path/to/submodule/
```

Git will treat these as regular tracked files from now on.

## Commit the changes

Bundle everything into a single commit:

```bash
$ git commit -m "Replace submodule with local files"
$ git push
```

Your collaborators will get the change cleanly on their next pull. The directory is now a standard part of the repository.

For more on submodule management, see the [`git submodule` reference](/git/commands/git-submodule). Related commands: [`git add`](/git/commands/add) and [`git commit`](/git/committing-file-changes).

---

[DeployHQ](https://deployhq.com) handles submodule checkouts during deployment automatically. [Try it free](https://deployhq.com/signup).
