10

I did some work on the wrong branch; I forgot to check out the right branch. Is it possible to change to the other branch and commit my changes there?

Giacomo1968
  • 58,727
Ravenix
  • 291

2 Answers2

14

Depending on the types of changes you make, you may not be able to just switch branches. If that is the case, you can use the git stash command to allow you to change branches. Just use the following commands:

git stash
git checkout <new_branch>
git stash pop
heavyd
  • 65,321
1

When my changes are not comitted yet. I could just checkout the right branch. The changes will be still there. Just checkout the-right-branch and then you can commit your changes in the-right-branch. Thanks all for reacting.

Ravenix
  • 291