How to sync a local repo so that any local submodules which aren't in remote are wiped?

84 views Asked by At

Let's say you have a local repo and want it to be exactly as the last commit in your remote repo.

These are the steps that I'm typing in order to achieve this:

cd <main repo>
git clean -fxd       (clean all untracked files that aren't submodules)
git submodule foreach git clean -fxd     (clean all untracked files in submodules)
git reset --hard             (clean all uncommited changes in our main repo)
git submodule foreach git reset --hard    (clean all uncommited changes in submodules)

git submodule update --init --recursive         (update all submodules with one on remote repo)

The problem is that these won't delete any extra submodules that are in my local repo but not in the remote repo.

Any help in improving my series of steps would be greatly appreciated.

1

There are 1 answers

0
jthill On BEST ANSWER

From the docs:

If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f or -i. Git will refuse to modify untracked nested git repositories (directories with a .git subdirectory) unless a second -f is given.

so git clean -dffx