Remove Git Submodule Note
Posted on: September 01, 2023
Remove remote origin
After cloning a git repository from someone else, we want to remove its remote origin and add our own remote origin to push to our github:
Bash
# Remove remote origingit remote rm origin# Add our own remote origingit remote add origin git@github.com:<username>/<gitrepo_name>.git
Remove submodule
Sometimes we would like to push a repository that already has another git repository inside, we could add that git repo as a submodule, but sometimes we want to remove that submodule:
Bash
# Navigate inside the outer repository (the one above the submodule)cd path/to/directory# Remove the submodule from its trackinggit rm -r --cached <submodule_repo># Check to see that the submodule repo is untrackedgit status# Remove the .git folder in submodulerm -rf <submodule_repo>/.git# Now you can add and push the repogit add <submodule_repo>git commit -m "Fix submodule"git push