Tuesday, August 21, 2012

Git Version Control Quick Reference Guide

This is a quick reference guide I made for Git Development. We made the switch over to Git and haven't looked back. We use Git for everything now, Microsoft, iOS, Android, Rails and Node.js development. Combined with Redmine and you have one of the most amazing source control, issue tracking and project management tools around.

Git Workflow and Branching Model

I borrowed the graphic above from Nvie.com since it illustrates a very simple way to use git.

Every day when a developer comes in, they should do a “git pull” from the develop branch. This ensures they always have the latest version of code from the develop branch. When they are done with their work, they should “merge”
Develop Branch
git checkout -b develop origin/develop
git pull
Branch already exists and push to remote
git checkout develop

Branch from develop to local branch
For smaller projects you can checkout based on username.
git checkout -b develop-{username} develop

git checkout -b develop-user develop

For larger projects or if you have multiple features or bug fixes to checkout

git checkout -b develop-{feature} develop

git checkout -b develop-{bugfix} develop
Add files
git add .

commit to local repository
git commit -am “comment”

push to remote repository
git push


Merging from your local development branch to the main development branch

git checkout develop
git merge develop-user develop

Assuming there are not merge conflicts, the merge will run successfully

Deleting a Branch

git branch -d {branch name}


git branch -d develop-user

Release Developers
Release developers are responsible for creating the release branches and merging the main develop branch into the release branches

Creating a Remote Release Branch
This creates a release branch based based on the current develop branch

git checkout -b release-1.0.0 develop
git push origin release-1.0.0

Merging Develop Changes into the Release Branch and Push
git checkout -b develop origin/develop
git pull
git checkout release-1.0.0
git merge develop
git push

Production Developers and Production Administrators
Production Developers and Production Administrators are responsible for maintaining the master branch and merging changes from the release branch into the master branch.

Merging from a Release Branch to a Master Branch and Deploy to Production
git checkout master
git merge release-1.0.0
git push

Versioning Master Code
git checkout master
git tag -a 1.0.0 -m “Version 1.0.0 added”
git push --tags

Merging Release Branch Code back to develop
git checkout -b develop origin/develop
git merge release-1.0.0
git push

Remove the Release Branch
Once you are done with the release branch remove it locally and remotely

git branch -d release-1.0.0
git push origin :release-1.0.0

No comments: