Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git, how do you move some uncommitted changes from one branch to another branch in a different folder?

Tags:

git

I have two different branches of the same software that I work on every day. However, every time I checkout the other branch, my build process can take up to an hour. To solve this, I have just checked out the project once for each branch in two separate folders.

I did some work in one branch, and realized before committing it that I was in the wrong folder, and thus the wrong branch. How can I move the work I did on this branch, to the other branch, preferably without creating a commit (if that is even possible)?

like image 424
Cory Klein Avatar asked Jan 31 '11 19:01

Cory Klein


2 Answers

In the directory with the changes, do:

$ git diff > patch

cd to the other directory, and do:

git apply /path/to/patch
like image 182
William Pursell Avatar answered Sep 21 '22 13:09

William Pursell


Well, you can also not build the other branch..

  1. Make the change, don't commit
  2. Switch to the other branch
  3. Commit (don't build)
  4. Come back

Naturally, this only works if you can allow yourself to commit without building (reasonable in some scenarios).

like image 43
Assaf Lavie Avatar answered Sep 20 '22 13:09

Assaf Lavie