1

I have a change which has been committed and pushed to the remote of dev-branch and now I want to push this change also to the mainline.

The approach I could think of is that duplicate the changes in the local and then commit/push to the mainline, but this looks like would make a single change becomes irrelevant commits across dev-branch and mainline?

So what is the correct way to achieve this? Thank you.

Bostonian
  • 615
  • 7
  • 16
  • There is no such thing as committing a “change”. A commit is a snapshot of everything, at the time. It’s unclear what you wish to do or why it’s hard. – matt May 05 '20 at 22:13

2 Answers2

0

If you have a single commit that you want to report/replicate from one branch to another, the correct command is git cherry-pick (which can also be applied to a range of commits)

That might make a future merge between branches slightly harder, because of duplicate commits

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Isn't this what merge is for?

git checkout mainline
git pull origin mainline  # this should fast-forward
git merge dev-branch
git push origin mainline

EDIT: also could use a pull request for the same effect

Jeremi G
  • 405
  • 2
  • 8
  • No: merge would report the change *and all the other changes* of one branch to another. If the change is limited to a commit, `git cherry-pick` is the correct command. – VonC May 06 '20 at 05:45
  • Yeah I guess I misunterstood the use case – Jeremi G May 06 '20 at 05:48