Git submodule pull overwrite/discard any local changes
Asked Answered
S

4

7

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).

Subdue answered 6/1, 2013 at 12:14 Comment(0)
C
7

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.

If a submodule contains another submodules, it can be done recursively

# reset current directory
git reset --hard
# reset all submodules
git submodule foreach --recursive git reset --hard
Calcaneus answered 6/1, 2013 at 13:17 Comment(2)
do you git reset --hard from inside the submodule directory or from the parent directoryBangka
git reset --hard discards all changes in the current repository. If done inside submodule it will discard changes in submodule. If outside -- submodule will be left untouched.Calcaneus
R
0

This is what worked for me:

Change directory into the submodule then run this:

git checkout -f -b submodule-branch remotes/origin/submodule-branch
Retribution answered 8/7, 2015 at 19:6 Comment(0)
G
0

git submodule update --remote --force pathToSubmodude

Gentry answered 21/9, 2020 at 16:19 Comment(0)
E
-4

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

Evaluate answered 6/1, 2013 at 12:18 Comment(1)
I'll do that if I have to but I would rather not delete and re-add the submodule.Subdue

© 2022 - 2024 — McMap. All rights reserved.