Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take all my changes on the current branch and move them to a new branch in Git

Tags:

git

branch

I started work on what I thought would be a minor bug fix on my master branch. However, it has spiraled out of control to the point where I wish I had created a separate branch to do the development in the first place.

So right now what I'd like to do is:

  1. Create a new branch called (say) "edge"
  2. Move all the changed / untracked files on master to edge (such that master is unchanged from when I started the bug fix)
  3. Finish my work on edge, merge back into master

How can I do this?

like image 379
Tom Lehman Avatar asked Sep 09 '09 08:09

Tom Lehman


People also ask

Can I create a new branch with current changes?

You can do a checkout and create a new branch with all local and current changes transferred over.


1 Answers

If you haven't been committing anything yet, you're already in the right position.

  1. Create a new branch: git checkout -b edge
  2. Your files haven't changed. Just git add what needs to and commit as usual.
  3. When you're done committing on edge, switch back to master with git checkout and git merge edge.
like image 95
JB. Avatar answered Oct 16 '22 17:10

JB.