logoalt Hacker News

miggoltoday at 9:47 AM1 replyview on HN

A slight limitation of worktrees is that you can only have a branch checked out once in all of your worktrees. I guess that's just how git works.

But when I want to checkout a branch that's already checked out in another worktree, Magit just plain refuses. I wish it would offer me to either:

1. Switch to that worktree instead

2. Detach head in the other worktree and checkout here

Would be such an improvement! No excuses though, I love magit and might as well hack this myself. I'm just bad at elisp.


Replies

svlasovtoday at 9:55 AM

> I guess that's just how git works.

You can use `--force`:

> If <branch> does exist, it will be checked out in the new worktree, if it’s not checked out anywhere else, otherwise the command will refuse to create the worktree (unless --force is used).