Github – How to create a dev branch


Recently I have been using github alot for simple apps. So far I have only used the master branch. I want to switch my workflow and have only production ready code on the master and do all of my development on the “dev” branch. The key concept is to never modify any code on the master branch, all code will be modified on the dev branch then merged with the prod branch after it has been tested.

First navigate to the repo in git bash and make sure your master branch is up to date and all your latest commits are psuhed to github.

Master up to date?

git status
git add .
git commit -m “adding dev branch”
git push origin master

Next create a dev branch.

Create Branch

git branch dev
git checkout dev

Now you are in the “dev” branch. Modify some code, all the changes will be made to the dev branch. The goal is to commit changes locally and push to the Github repo periodically. It would be nice to set up an Appharbor (or whatever provider) hook to deploy the dev branch to a dev web server and the master branch to a prod web server.

After a file is modified in the repo, add the change to the dev branch.

Add change to Dev Branch

git add changedFile.txt
git commit -m “changed file in dev”

Push to the dev branch on Github

git push origin dev

At this point an Appharbor hook could deploy the code to the dev server. Then testing would occur. If the dev code looks good then merge and push the new feature to the master (prod).

Add new Dev feature (merge) to Master and push to Github

git checkout master
git merge dev
git commit -m “Added a new feature from dev”
git push origin master

If you completely messed up, you can delete the dev branch and start a new branch from scratch. You accomplish this by switching to the master branch and force delete the dev branch locally, then on Github.

Delete entire branch

git checkout master
git branch -D dev
git push origin –delete dev



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s