Skip to main content
Well, I'm not really guessing. I know how git works.
Source Link
Erik B
  • 42.1k
  • 27
  • 123
  • 140

I recently ran into this problem again. It's been a while since I last worked with submodules and having learned more about git I realized that simply checking out the branch you want to commit on is sufficient. Git will keep the working tree even if you don't stash it.

git checkout existing_branch_name

I guess ifIf you want to work on a new branch this should work for you.:

git checkout -b new_branch_name

I guess the mergeThe checkout will fail if you have conflicts in the working tree, but that should be quite unusual and if it happens you can just stash it, pop it and resolve the conflict.

Compared to the accepted answer, this answer will save you the execution of two commands, that doesn'tdon't really take that long to execute anyway. Therefore I will not accept this answer, unless it miraculously gets more upvotes (or at least close) than the currently accepted answer.

I recently ran into this problem again. It's been a while since I last worked with submodules and having learned more about git I realized that simply checking out the branch you want to commit on is sufficient. Git will keep the working tree even if you don't stash it.

git checkout existing_branch_name

I guess if you want to work on a new branch this should work for you.

git checkout -b new_branch_name

I guess the merge will fail if you have conflicts in the working tree, but that should be quite unusual and if it happens you can just stash it, pop it and resolve the conflict.

Compared to the accepted answer, this answer will save you the execution of two commands, that doesn't really take that long to execute anyway. Therefore I will not accept this answer, unless it miraculously gets more upvotes (or at least close) than the currently accepted answer.

I recently ran into this problem again. It's been a while since I last worked with submodules and having learned more about git I realized that simply checking out the branch you want to commit on is sufficient. Git will keep the working tree even if you don't stash it.

git checkout existing_branch_name

If you want to work on a new branch this should work for you:

git checkout -b new_branch_name

The checkout will fail if you have conflicts in the working tree, but that should be quite unusual and if it happens you can just stash it, pop it and resolve the conflict.

Compared to the accepted answer, this answer will save you the execution of two commands, that don't really take that long to execute anyway. Therefore I will not accept this answer, unless it miraculously gets more upvotes (or at least close) than the currently accepted answer.

Source Link
Erik B
  • 42.1k
  • 27
  • 123
  • 140

I recently ran into this problem again. It's been a while since I last worked with submodules and having learned more about git I realized that simply checking out the branch you want to commit on is sufficient. Git will keep the working tree even if you don't stash it.

git checkout existing_branch_name

I guess if you want to work on a new branch this should work for you.

git checkout -b new_branch_name

I guess the merge will fail if you have conflicts in the working tree, but that should be quite unusual and if it happens you can just stash it, pop it and resolve the conflict.

Compared to the accepted answer, this answer will save you the execution of two commands, that doesn't really take that long to execute anyway. Therefore I will not accept this answer, unless it miraculously gets more upvotes (or at least close) than the currently accepted answer.