The Computer Oracle

Accidentally worked on wrong branch in Git

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Puzzle2

--

Chapters
00:00 Accidentally Worked On Wrong Branch In Git
00:18 Accepted Answer Score 14
00:41 Answer 2 Score 1
00:59 Thank you

--

Full question
https://superuser.com/questions/973892/a...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#git #branch

#avk47



ACCEPTED ANSWER

Score 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



ANSWER 2

Score 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.