- Open a branch in a new folder
git worktree add ../myapp-hotfix hotfixRun this inside your project. Git checks out the branch in a folder next to your project, so your current work stays as it is.
- Or make a new branch in a new folder
git worktree add -b hotfix ../myapp-hotfixUse this when the branch does not exist yet. It starts from the commit you are on now.
- Go to the new folder and work there
cd ../myapp-hotfixEdit, commit and push here like in any project. Both folders share the same history, so commits show up in both.
Check it worked
- List every folder and the branch it has
git worktree list
Undo it
- Remove the extra folder when you are done
git worktree remove ../myapp-hotfixRun this from your main project folder. The branch and its commits stay. Git refuses if the folder has changes you have not committed.
- Clean up folders you deleted by hand
git worktree prune
- Open a branch in a new folder
git worktree add ../myapp-hotfix hotfixRun this inside your project. Git checks out the branch in a folder next to your project, so your current work stays as it is.
- Or make a new branch in a new folder
git worktree add -b hotfix ../myapp-hotfixUse this when the branch does not exist yet. It starts from the commit you are on now.
- Go to the new folder and work there
cd ../myapp-hotfixEdit, commit and push here like in any project. Both folders share the same history, so commits show up in both.
Check it worked
- List every folder and the branch it has
git worktree list
Undo it
- Remove the extra folder when you are done
git worktree remove ../myapp-hotfixRun this from your main project folder. The branch and its commits stay. Git refuses if the folder has changes you have not committed.
- Clean up folders you deleted by hand
git worktree prune
- Open a branch in a new folder
git worktree add ../myapp-hotfix hotfixRun this inside your project. Git checks out the branch in a folder next to your project, so your current work stays as it is.
- Or make a new branch in a new folder
git worktree add -b hotfix ../myapp-hotfixUse this when the branch does not exist yet. It starts from the commit you are on now.
- Go to the new folder and work there
cd ../myapp-hotfixEdit, commit and push here like in any project. Both folders share the same history, so commits show up in both.
Check it worked
- List every folder and the branch it has
git worktree list
Undo it
- Remove the extra folder when you are done
git worktree remove ../myapp-hotfixRun this from your main project folder. The branch and its commits stay. Git refuses if the folder has changes you have not committed.
- Clean up folders you deleted by hand
git worktree prune

New to Branch? I explain it in plain English on Layman Terms.