My question may not be of a standard way of using git, but I have a branch (denoted A) that implements some features and may take very long time to approve. It is not yet merged to master. Now I'm working on branch B and would like to have features from A to do debugging. But I do not want to merge A into B because it will pollute my commit history. Is it possible to tell git to merge but keep thing unstaged?
-
If my answer help you out, I would be very happy if you could accept it as solution. If not, I would appreciate to hear why. Cheers, Tommy – tomwaitforitmy Jan 31 '23 at 08:00
-
@tomwaitforitmy your alternative solution works and it keeps thing staged, which is also fine for me. – kstn Jan 31 '23 at 13:48
2 Answers
One simple solution is to create a new branch "C" as a copy of B and merge A into C. This way B stays as it is, but you can still test everything you like. That's what I would personally prefer, because it seems to me what you actually would like to achieve. You don't have to publish C, but you have the option to publish it, for instance if the merge is complex and you want to save that.
Another alternative is
git merge <name-of-branch> --no-commit --no-ff
Here you can find more details: Git merge without auto commit

- 509
- 3
- 16
You can have B
on top of A
then, when you decide that B
is ready to be merged into branch mainOrMaster
, you can do this to clear it up of what you have in A
:
git rebase A B --onto mainOrMaster
That will get all commits that make up B
that are not part of A
and will put them on top of mainOrMaster
.

- 26,375
- 3
- 36
- 60