You can use git worktree
for this task.
Git worktree use a single repo and allow you to checkout any desired branch on different folders.
Git had this ability since 2007. Under cotrib
folder the was an hidden command named 'new-workdir' which was later on added to gin inversion 2.5
and was renamed to git worktree
.
git worktree
git worktree
will create a new working folder allow us to work on multiple branches on the same time. each copy will point to the origin repository while the 3-states
is a new and fresh copy. This save us the need to use git stash
or even to clone a new repository since those worktree shares the same repo we can checkout any branch on any worktree, we can do a cherry-pick or merge and all will be done locally on our machine.
Usage:
git worktree add <second path>
will create another folder on your computer which allow you to work on different branch simultaneously.
This will allow you do to any experimentals on the new worktree without having any effect on the repository itself. In the attached image you can see that there are 2 separate working folder but both of them are using a single repo and share the content.

Now since the 2 worktree
shares the same .git
folder you can use git cherry-pick
to grab any commit or file for a specific commit and add it to any existing worktree
that you have created.
