On my local repo I have the main working tree full of many unrelated changes.
I want to split my messy index into many distinct tidy linked worktrees, so I can isolate changes by concern and handle them without getting insane or rely on memory.
What's the minimal amount of steps to redistribute chunks among different worktrees?
Example
$ git status
M .env
M .gitignore
M Dockerfile
M README.md
?? untracked.file
?? worktree/
I would
- use
git stash save Concern001 -p
, to interactively select the changes I want to put into Concern001 - to then
git stash apply Concern001
into my worktree- (created via
git worktree add worktree/Concern001
).\
- (created via
But this approach fails in the case I want to move untracked changes to another worktree. Trying git stash save Concern001 -p -u
Can't use --patch and --include-untracked or --all at the same time
Moreover, the presence of the worktree/
directory among the untracked files makes the stashing error prone; although I can fix this adding /worktree
to .gitignore
.
For now I tried:
git add -p
to select the changes to isolategit commit -m 'Concern001'
=> commit-SHAcd worktree/Concern001
git cherry-pick <commit-SHA>
git reset HEAD^
to get again the changes in the worktree indexcd ../..
(back to main worktree)git reset HEAD^
..... but this will restore the changes I just moved away; and if I instead usegit reset HEAD^ --hard
then I would loose all the other temporary changes from the index.
This approach look verbose, cumbersome and error prone.
Is there a sequence of git
commands to select specific changes and move them between worktrees, without having to do too many intermediate operations❓</h3>
Ideally I'd use git stash
but doesn't cover all the use cases.