Convert a Given Git Branch to Master and Retain History


 AMP

Introduction and Overview of Steps:

In order to migrate from Laravel 4.2 to Laravel 5 when it initially came out, I created a new branch and began to work through the uprade. My intention initially was to merge the branch back into master, but never got around to it. After so much time (and something like 500 commits later) I decided to just make the Laravel 5 branch (called 'new_master' below) the new master branch using the following steps:

git checkout new_master
git merge --strategy=ours --no-commit master
git commit -am 'changing branch "new_master" to "master"'
git checkout master
git merge new_master

Step 1 - Checkout the 'new_master' Branch

ubuntu /var/www/test $ sudo git checkout new_master

Step 2 - Merge

ubuntu /var/www/test $ sudo git merge --strategy=ours --no-commit master
Automatic merge went well; stopped before committing as requested

Step 3 - Add a Commit Including a Helpful Message

ubuntu /var/www/test $ sudo git commit -am 'changing branch "new_master" to "master"'
[new_master 5b19bcf] changing branch "new_master" to "master"

Step 4 - Checkout 'master' Branch

ubuntu /var/www/test $ sudo git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

Step 5 - Merge 'new_master' Branch

ubuntu /var/www/test $ sudo git merge new_master

Step 6 - Check Git Status

ubuntu /var/www/test $ git status
On branch master
Your branch is ahead of 'origin/master' by 544 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

Step 7 - Push to Branch 'master'

ubuntu /var/www/test $ sudo git push origin master
Counting objects: 1, done.
Writing objects: 100% (1/1), 238 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To git@github.com:test/test.git
   fef1e53..5b19bcf  master -> master

After completing the above steps successfully in a test environment, all that was left to do on the production server was to checkout the master branch with a `git checkout master` and run a single `git pull origin master`.


Tags:  Linux Git

Comments:


Gravatar of Kyle Jones

Knowledge Base is a repository for various notes, guides, and thoughts on a wide range of IT related topics. Read more...