6

I have a git (and Github) repo with a master branch, a development branch and several feature branches. Each of the feature branches have been branched off development and subsequently merged into development.

I'd now like to "promote" development to master. I don't want to merge these two branches because conflicts may arise. Essentially, development is "production ready" and I'd like for master to reflect the current state of development. How can I do this?

Paymahn Moghadasian
  • 9,301
  • 13
  • 56
  • 94
  • What do you want to do to the history of `master`? – SLaks Feb 04 '15 at 18:53
  • Has development also been branched off master (usually the case, but you might have different setup)? If so, what do you want to do with commits after their common ancestor? – Ma3x Feb 04 '15 at 18:54
  • Possible duplicate of: http://stackoverflow.com/questions/2763006/change-the-current-branch-to-master-in-git – vsnyc Feb 04 '15 at 18:55
  • I'd like to overwrite (maybe extend is the right word) the history of ```master```. The idea is that all work is done on ```development``` and at regular intervals ```development``` is promoted ```master```. – Paymahn Moghadasian Feb 04 '15 at 21:12

2 Answers2

5

In other words, develop is your new master. The easiest way to do that would be to simply push developer to master:

 git push origin origin/development:master

This will work if development started from current master. If not, and you don't want to keep the history of the master you can force the push:

git push -f origin/development:master 

The problem with the forced push might arise if there is other work (branches) forked from master. In such case the safest approach would be to do a technical merge as described in the answers to earlier mentioned thread.

Community
  • 1
  • 1
Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27
  • I'm having the same problem with the team foundation server. I want to promote a child branch as the trunk branch without losing the history of both branches. Is there a workaround in TFS to solve this issue. – Sachith Wickramaarachchi Oct 09 '19 at 08:55
  • @Sachith TFS has nothing to do with git. Creating a new dedicated question might be a good idea for you. – Mykola Gurov Oct 13 '19 at 16:50
5

I think that is better to have a merge commit when declaring develop as ready for production, so that you can roll back.

While this is perfectly doable with plain git commands, I have a script to do all the steps: https://gist.github.com/soulrebel/9c47ee936cfce9dcb725

In practice this is what a promote command does:

git pull --ff-only         # check we are up to date on our branch
git checkout master        # go the target branch
git pull --ff-only         # check updates there too
git merge develop --no-ff  # merge with a commit
git push                   # push the merge
git checkout develop       # back to develop
Andrea Ratto
  • 815
  • 1
  • 11
  • 23
  • Please describe what the script does a little more; otherwise it's a link-only answer that's supposedly bad for stackoverflow – Dima Tisnek Dec 01 '15 at 11:37
  • Show how to do this without the script. – Holloway Dec 01 '15 at 11:38
  • @AndreaRatto I'm having the same problem with the team foundation server. I want to promote a child branch as the trunk branch without losing the history of both branches. Is there a workaround in TFS to solve this issue. – Sachith Wickramaarachchi Oct 09 '19 at 08:56