worktree switching branch without stash
Some times you are working on some feature but then you need to check or fix something on some other branch. The normal way to do it is that we do:
  1. 1.
    git stash
  2. 2.
    switch to other branch
  3. 3.
    commit changes
  4. 4.
    swith to previous branch
  5. 5.
    git stash pop
This can be complicated especially you have multiple stash. You can't easily understand which stash belongs where.
After version 2.5.2 there is new command called git worktree
Basically it can create new directory which checkout different branch
example
1
$ git worktree add ../branch-temp some-branch
2
$ cd ../branch-temp
3
​
4
// hack
5
// finish
6
​
7
$ cd ../original-path
8
$ rm -rf ../branch-temp
9
​
10
// cleanup
11
​
12
$ git worktree prune
Copied!
more detail about the command are available at https://git-scm.com/docs/git-worktree​
Last modified 1mo ago
Copy link