Git merge one branch into two other branches

10,256

Solution 1

This is exactly what git is useful for! Start your development on a branch off of master, let's call it "Feature". Then when you're ready to test, commit your changes to your feature branch and do the following:

git checkout UAT
git merge Feature

TEST TEST TEST

git checkout master
git merge Feature
git push origin master

This will get your test code into both the UAT and master branches

Solution 2

You can use git cherry-pick to add the branch to your UAT branch.

Share:
10,256
aspnetdeveloper
Author by

aspnetdeveloper

Updated on June 05, 2022

Comments

  • aspnetdeveloper
    aspnetdeveloper almost 2 years

    How can I merge one branch in to two other branches?

    So here's our scenario: We use two branches master for production and UAT for testing purposes. All local development is made on a new branch made off of Master so before starting on something, we create a branch off of master, commit and push it to origin/master. For bigger projects we use UAT for testing purposes.

    I have a branch which is ready to be tested and then pushed to production. How can I move that branch to UAT so people can test it and once tested move the same branch from my local machine or from UAT to Master?

  • huggie
    huggie about 10 years
    Suppose there are already some prior differences between master and UAT before working on Feature. (Say there are a few commit on master that UAT doesn't have). After working on Feature, does git checkout UAT, git merge Feature merges that prior difference into UAT as well?
  • huggie
    huggie about 10 years
    I checked it and it did.
  • ChrisWue
    ChrisWue over 8 years
    The problem with cherry picking is that you only have very limited visibility on what got cherry picked and what not. This can be a problem on larger branches where multiple people are working on it. Merging is a lot better in that case from my experience
  • dan carter
    dan carter over 4 years
    this will merge all the changes from master into UAT!