Simple daily git workflow
I've been looking for an everyday guide to git for a simpleton. The git simpleton in question is me.
One of the key things that Arun has brought to my programming is the rigor of working in a multi-developer environment, an area in which my experience is weak. I've worked in larger groups as a designer, but it's possible to sit outside the flow of development lifecycle and drop HTML templates into the process.
However even I understand the importance of version control, and the emergence of git as the source control of choice (and the all marvelous github) mean I have been using git but only in a cack-handed way. What I was missing was the regular day-to-day repeatable how. If you're familiar with source control, this is not going to be big news, but I want to capture this as I'm still learning as its only really this week I feel I 'get it'. So here it is, I've even created a cheatsheet, which you can download at the end of the article.
There's load of ways to install git (standard setup article is under construction) so whether you want to install from source or download an installer, knock yourself out.
Simple Daily Git Workflow Once you've set up your repository on Github (go ahead a buy a nice plan while you're there) this is process we're following for every line of code we right:
Before you do anything make sure you're up to date with all the changes made on the remote master branch by other developers.
git checkout master git pull We like to make a branch for every issue/bug/feature we're trying to build so we start a new branch for each, this gives us the ability to always have deployable code in the master branch. We can also abandon branches where we've gone wrong and always head back to master, like insurance!
git checkout -b your-branch-name-here This creates a new branch for you to start making you changes and switches you into it.
Do your work here! The key thing to remember at this stage is to commit often, *really often* the smaller your commits the more you can undo any damage or later go back and see what you did. Whether its a change of layout of a single template or a single test passing commit it separately.
git status This shows you the files that have changed.
git add . This adds any new files you have created. You can add a series of specific individual files if you like, simply replace the dot e.g. 'git add your/filename/here'
git diff This shows the differences line by line. You could use GitX if you're on a Mac to deliver a lovelier graphical representation 'git diff | gitx'.
git commit -m "detailed message here" Commits your changes with a nice little informative message as to the changes you've made. At this stage if you feature/bug/issue isn't completed simply loop back up and do another small chunk of work!
Once your feature is complete or your bug is squashed it's time to bring the master branch up to date.
git checkout master git merge your-branch-name-here For your next feature or bug just create another new branch. For us we're linking all our branches to github issues, as Arun mentioned. So our branch names are all called issue-n to match up with that.
When you want to resynchronise with github.
git push Job done. For those of you who've made it this far you might be keen to download a pretty cheatsheet I've put together. I have pinned it behind my own monitor, lest I forget.
