Hasan's Blog

Checkout a branch without commiting/stashing local changes

ai-generated poster


this command copies the entire repo into a new tree that will appear as a sub dir. then you can explore that shit as you want knowing that the original tree is untouched.

example, I am at branch A and I want to check something at branch master:

git worktree add testTree master
cd testTree

the result of the above commands will be the creation of a new copy of your repo into a sub directory called testTree where the branch will be master. then we cd into that directory,

after finishing our work we can easily delete the sub directory:

git worktree remove testTree

This project is maintained by hasan-aga