Git Submodule Pull Overwrite/Discard Any Local Changes

I have a submodule which I changed some local files. The original repository has been modified and I now wish to do a pull on the submodule, but I get an error saying that I will lose my changes.

How do I force git to ignore local changes and do the pull?

I know there are lot's of similar questions to this, but I couldn't find a question in stack overflow that answered my particular problem (specifically submodules).

4 Answers

git reset --hard does exactly that - discard all changes and return to HEAD.

Or you can use git stash and after pull - git stash apply to restore your changes over updated tree.

2

This is what worked for me:

Change directory into the submodule then run this:

git checkout -f -b submodule-branch remotes/origin/submodule-branch

git submodule update --remote --force pathToSubmodude

I have a very silly solution, just clone all the files elsewhere, delete your local submodules, and put the new ones in.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest