MR. D
MR. D

Reputation: 1

How to checkout between git branches while one has a directory and the other has a submodule under the same name and path?

In a large git repo, I need to maintain an old branch that has a directory named NAME in its root dir. Somewhere along the way, git submodules were introduced to the project so that the directory became a submodule, and the submodule's name was defined NAME for consistency.

Now, when working on the current branch - NewBranchWithSubmodule, upon checkout to the old OldBranchWithDir, I get the following message:

user$ git checkout OldBranchWithDir
error: The following untracked working tree files would be overwritten by checkout:
       NAME/file
Please move or remove them before you switch branches.
Aborting

I've read about similar issues here, but none of which solved the issue sufficiently enough.

what is the proper way to checkout or to maintain such condition? (assuming a rename or moving the dir isn't an option)

Thanks!

Upvotes: 0

Views: 79

Answers (1)

jthill
jthill

Reputation: 60275

Switching between branches with submodules and trees recorded at the same path is annoying enough that the right way to do it is to set up a separate work tree for the old branches that have the abandoned setup there, your case is

git worktree add ../OldBranchWithDir

Upvotes: 2

Related Questions