3

How do one use multiple branches or switch branch without commit?

I'm using GIT with VisualStudio and are working in one branch when a colleague of mine ask me to to something in another. I do not want to commit changes in my first branch. How do I use two branches simultaneously or how do I switch branches without committing pending changes?

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
UlfL
  • 59
  • 1
  • 3
  • 3
    you can [stash](https://git-scm.com/docs/git-stash) your work in your current branch, checkout the other branch, help your colleague, and the checkout your branch, and apply the stash content it again – William Kinaan Jun 18 '19 at 09:07
  • You can also try `git worktree`. See https://stackoverflow.com/a/45491767/6330106 – ElpieKay Jun 18 '19 at 09:57

1 Answers1

3

When you have uncommitted changes in a branch and you want to switch to another branch you can use git stash to temporarily "save" the changes without committing them.

When you switch back to the branch you can use git stash pop to reapply your changes to the branch.

You can also do more advanced stuff with stash, see the Git Pro book Chapter about it for more.

If you are using Visual Studio 2019 you can stash directly in the Team Explorer, for the 2017 version you can use this extension if you don't want to use the terminal.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
maxiangelo
  • 125
  • 12