Home > Back-end >  use commits from other branch but not merge
use commits from other branch but not merge

Time:01-27

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?

CodePudding user response:

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

CodePudding user response:

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.

  •  Tags:  
  • git
  • Related