2

Say you have these two branches -

*p1
p2

Now you did some file changes on p1 and you want to checkout to p2. But git didn't allow you to do that. What is that situation where git doesn't allow you to checkout?
Actually, I faced this issue once but I am not able to remember that situation and now I am confused because now, git is allowing to checkout to another branch after doing some file changes.
Could you please provide a situation where git isn't allowing to do that?

supernatural
  • 1,107
  • 11
  • 34
  • The two already-added answers are not _quite_ correct. Git will allow you to move **without any issues** if the place where you want to go to has the-files-you-modified exactly as they are on HEAD (as in, they don't change between the revision you are on and the revision you want to go to). If any of those files (the ones you modified) changes between HEAD and the place where you want to go to, git refuses to move. – eftshift0 Feb 11 '20 at 20:22

2 Answers2

2

You need to commit the changes or stash them and pop in the other branch, or you can discard the changes.

WilsonPena
  • 1,451
  • 2
  • 18
  • 37
1

You cannot checkout to another branch, until you add . and commit your changes