1

I have two branch

  • dev
  • feature

Unconsciously I have written some code in dev branch that are not allowed in dev branch without testing. I don't want to loss all the code that I have written. Now I want to switch feature branch and added all changed files in feature branch. But when I want to checkout feature branch it shows

Please commit your changes or stash them before you switch branches

There is any way to switch feature branch and get all changed files in feature branch so that i add those file in feature branch.

phd
  • 82,685
  • 13
  • 120
  • 165
Mahfuz Shishir
  • 841
  • 1
  • 7
  • 24
  • https://stackoverflow.com/search?q=%5Bgit%5D+Please+commit+your+changes+or+stash+them+before+you+switch+branches – phd Aug 20 '20 at 14:00

1 Answers1

7

As git is telling you, you can either commit the changes or stash them.

The easiest solution here is to stash them:

# Assuming you are on dev branch
$ git stash save "Code in dev branch to be included in feature branch"
$ git checkout feature
$ git stash pop 

your changes are now available in feature.

Paolo
  • 21,270
  • 6
  • 38
  • 69