Preparing the Alpha Git repo for Gitflow

A description of the sequence of Git commands I needed to run to prepare the Alpha Git repo for the Gitflow branching model.

Introduction

Recently I have been spending some time getting familiar with the Gitflow branching and tagging model, as we are rolling it out in my organization. I decided it would be an opportune time to also convert the Git repo for Alpha to that model, and here are the commands I ran in sequence to do so.

Renaming the master branch

Presently the old 1.x release of Alpha it sitting on the master branch, while the latest 2.x code is sitting on the 2.0.0 branch. Using the Gitflow approach, the latest production-ready code should be sitting on your master branch and tagged as releases, therefore the first thing I needed to do was rename the current master branch to a new 1.x branch to hold the old code for archival purposes (considering this code is tagged anyway, I might actually drop the 1.x branch at some point).

Here are the commands to rename master to 1.x. Note that this will remove the master branch on the remote repo!

git branch -m master 1.x
git push origin :master

Rename 2.0.0 to master

Next up I needed to rename the 2.0.0 branch to master, effectively creating a new master branch with the latest code:

git checkout 2.0.0
git branch -m 2.0.0 master
git push origin :refs/heads/2.0.0
git push --set-upstream origin master

Now we have a 1.x branch with the legacy code, and a master branch with the latest code.

Create a new develop branch

In the Gitflow model there should only really be two permanent branches: the master branch with the latest production-quality code, and the develop code with the latest feature developments. Now it was time to create a new develop branch, which is simply a new branch off master:

git checkout master
git checkout -b develop
git push origin develop

Conclusion

I intend to write more about Gitflow in a follow-on article, and in the interim will continue to follow this approach for future Alpha developments. You can see the updated repo on Github here.

John Collins

I have been writing about web technology and software development since 2001. I am the developer of the Alpha Framework for PHP, and the five.today personal productivity app. I love open source, technology, and economics.

Alpha Framework 2.0 Beta

Developing off the Alpha trunk