Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
You want git worktree: https://git-scm.com/docs/git-worktree. The idea is that you can have multiple branches of the same repository checked out to different directories, but they're still the "sa...
Answer
#2: Post edited
- You want `git worktree`: https://git-scm.com/docs/git-worktree.
The idea is that you can have multiple copies of the same repository checked out to different directories, but they're still the "same" repository locally. I've used this technique precisely to avoid having to re-download `node_modules` when switching branches, among other related problems.- The main disadvantage to `git worktree` is that you cannot have the same branch checked out in multiple directories. That restriction is sensible, as it would be hard to sync the changes between the directories otherwise, but it's occasionally annoying. To work around this annoyance, I'll create a local branch like `fake-branch` that tracks `main`, `develop`, etc. (whatever the main branch is) and use `fake-branch` as the "resting" branch for my secondary directory. That way, if I accidentally switch to the main branch in my "normal" directory, I don't get an error.
- You want `git worktree`: https://git-scm.com/docs/git-worktree.
- The idea is that you can have multiple branches of the same repository checked out to different directories, but they're still the "same" repository locally. I've used this technique precisely to avoid having to re-download `node_modules` when switching branches, among other related problems.
- The main disadvantage to `git worktree` is that you cannot have the same branch checked out in multiple directories. That restriction is sensible, as it would be hard to sync the changes between the directories otherwise, but it's occasionally annoying. To work around this annoyance, I'll create a local branch like `fake-branch` that tracks `main`, `develop`, etc. (whatever the main branch is) and use `fake-branch` as the "resting" branch for my secondary directory. That way, if I accidentally switch to the main branch in my "normal" directory, I don't get an error.
#1: Initial revision
You want `git worktree`: https://git-scm.com/docs/git-worktree. The idea is that you can have multiple copies of the same repository checked out to different directories, but they're still the "same" repository locally. I've used this technique precisely to avoid having to re-download `node_modules` when switching branches, among other related problems. The main disadvantage to `git worktree` is that you cannot have the same branch checked out in multiple directories. That restriction is sensible, as it would be hard to sync the changes between the directories otherwise, but it's occasionally annoying. To work around this annoyance, I'll create a local branch like `fake-branch` that tracks `main`, `develop`, etc. (whatever the main branch is) and use `fake-branch` as the "resting" branch for my secondary directory. That way, if I accidentally switch to the main branch in my "normal" directory, I don't get an error.