Search code examples
gitsmartgit

Committing local changes after branches are switched


I am supposed to work on git branch A, I however was unconsciously working on branch B. After noticing, my intention now is to switch to branch A without committing to branch B. After switching to branch A, I can do my commits. How do I achieve this using smart git?

PS: I have not committed to branch B at all


Solution

  • If you have not committed your changes to branch-b, then stash should work:

    > git stash
    > git checkout branch-a
    > git stash apply