# 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. git stash
2. switch to other branch
3. commit changes
4. swith to previous branch
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

```
$ git worktree add ../branch-temp some-branch
$ cd ../branch-temp

// hack
// finish

$ cd ../original-path
$ rm -rf ../branch-temp

// cleanup

$ git worktree prune
```

more detail about the command are available at <https://git-scm.com/docs/git-worktree>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.yulrizka.com/git/worktree-switching-branch-without-stash.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
