GitWorktrees

nicolaw 25th May 2018 at 10:26am
Git

https://stacktoheap.com/blog/2016/01/19/using-multiple-worktrees-with-git/

Have you ever needed to work on multiple branches of the same Git repository at the same time, and tire of having to either stash or commit and then checkout the other branches,... or if you're literally working on all branches concurrently, having to make multiple git clones of the same repository?

...well tire no more. Use a Git worktree.

$ git clone git@github.com:jdoe/twangles.git
$ cd twangles
$ git checkout -b feature/foo-bar
$ git worktree add -b feature/moo-baz ../twangles2 origin/master 
$ git worktree add -b feature/meep-meep ../twangles3 origin/master
$ cd ../twangles2
$ git rev-parse --abbrev-ref HEAD
feature/moo-baz
$ cd ../twangles3
$ git rev-parse --abbrev-ref HEAD
feature/meep-meep