Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Howto move changes since last commit to a new branch

I have been working on a branch which we can call "A". I just realized that the code I have added since I last committed should rather be in a specific (experimental) branch, but not in "A". How can I commit the changes to a new branch and leave branch "A" as it was when I last committed?

like image 614
Siggi Avatar asked Jul 12 '10 12:07

Siggi


2 Answers

If the changes are staged or your working directory, you can simply checkout into a new branch like so:

git checkout -b branch_name

You can then commit directly into the new branch.

like image 144
Blair Holloway Avatar answered Oct 05 '22 18:10

Blair Holloway


git stash
git checkout branch-A
git stash pop
like image 21
Verhogen Avatar answered Oct 05 '22 16:10

Verhogen