1

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

mykoman
  • 1,715
  • 1
  • 19
  • 33
  • Have you already committed anything to branch B that was supposed to be on A? – TTT Jul 02 '20 at 19:20
  • @TTT No, I haven't – mykoman Jul 02 '20 at 19:25
  • Does this answer your question? [git switch branch without discarding local changes](https://stackoverflow.com/questions/22082307/git-switch-branch-without-discarding-local-changes) – TTT Jul 02 '20 at 19:32
  • @TTT no, the questions are different, I haven't committed changes in the wrong branch at all in my own case. I noticed before making commits – mykoman Jul 02 '20 at 19:39
  • The fact that you didn't commit yet is what makes it a duplicate. ;) – TTT Jul 02 '20 at 19:45
  • 1
    To clarify, in both your situation and the question I linked to, you have some pending changes which you want to commit to some other branch instead of the one you are currently on. The answer below describes exactly what you need to do, and so does the answer in the linked question. – TTT Jul 02 '20 at 19:49

1 Answers1

1

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

> git stash
> git checkout branch-a
> git stash apply
Brent Worden
  • 10,624
  • 7
  • 52
  • 57