304

Possible Duplicate:
Move existing, uncommited work to a new branch in Git

I have some code in branch ABC.

After making some changes to it, i'd like to move all those uncommitted changes into a commit on a new branch ABC_1.

How can this be done please?

Community
  • 1
  • 1
James Raitsev
  • 92,517
  • 154
  • 335
  • 470

3 Answers3

496

Just create a new branch:

git checkout -b newBranch

And if you do git status you'll see that the state of the code hasn't changed and you can commit it to the new branch.

Abizern
  • 146,289
  • 39
  • 203
  • 257
  • 3
    is there a way to push changes to an existing branch without committing uncommitted code to present branch? – kRazzy R Jul 12 '18 at 20:51
  • 1
    @kRazzy R, probably a not-so-smart idea would be to create the new branch using `git checkout -b new_branch` and then merging the changes in the existing branch using `git merge` – markroxor Jan 11 '19 at 05:10
  • 2
    Git 2.23 adds the new switch subcommand in an attempt to clear some of the confusion that comes from the overloaded usage of checkout (switching branches, restoring files, detaching HEAD, etc.) https://stackoverflow.com/questions/1394797/move-existing-uncommitted-work-to-a-new-branch-in-git/1394804 – mohamad Aug 19 '20 at 11:59
51

Just move to the new branch. The uncommited changes get carried over.

git checkout -b ABC_1

git commit -m <message>
rohit89
  • 5,745
  • 2
  • 25
  • 42
21

Just create a new branch with git checkout -b ABC_1; your uncommitted changes will be kept, and you then commit them to that branch.

CharlesB
  • 86,532
  • 28
  • 194
  • 218