Wednesday, September 14, 2011

Set default merge options for Git branches



Time for a little Git tip!

Suppose you are the integrator of a branch. It is your responsibility to merge different branches from your co-workers. You want to keep a linear history. I.e. you want to avoid this:


Simply configure your master branch like this:
git config branch.master.mergeoptions "--ff-only"
Now every time you want to merge a branch that does not create a linear history, you will get the following (rather direct) message:
fatal. Not possible to fast-forward, aborting.
Now you can rebase that branch and merge it again (or tell your co-worker to do that for you, the lazy git).

You can configure multiple options:
git config branch.master.mergeoptions "--ff-only –-squash"
This configures the branch so that it only accepts a linear history and squashes all commits into a single new commit.

Want to remove these merge options? Simply do:
git config --unset branch.master.mergeoptions
Remember that these options are local for your Git repository. You have to repeat them for every Git repository you clone.

Have fun and happy coding!

Friday, September 9, 2011

Custom MSBuild tasks to clone Git repositories and more…

Every good work of software starts by scratching a developer's personal itch.
Eric Raymond – The Cathedral and the Bazaar
I love Git. I like the way it completely changed my way of thinking about version control. It has completely replaced Subversion for my personal projects.
I also love MSBuild. It is in my opinion an underappreciated, flexible, extensible and relatively unknown technology that can handle all your build problems. It is my first choice as a build tool for all continuous integration projects.
MSBuild is effectively an untyped Lisp-2 with ugly XML syntax
snprbob86 on Reddit

MSBuild does have community tasks that integrate with different version control systems, but Git is not one of them. (The Git love is spreading slowly in the Windows community…)
What else to do but write my own custom MSBuild tasks that integrate with Git? So, I present MSBuildGitTasks

A typical use case for  MSBuildGitTasks in my MSBuild projects:
  • Clone a Git repository onto the build computer.
  • Switch to a specific branch in the newly cloned local repository.
  • Retrieve the SHA from the latest commit in that branch (to be used as version information for the build).
  • Start compiling…
MSBuildGitTasks is released as open source (with a GPL3 license) and can be found on my Github page. Pull requests/patches are welcomed. There’s also an issue tracker if you want to report anything.
I consider this a 0.1 release. It works for my workflow and my combination of hardware/software. That said, the software is extremely simple and should be easy to grok.


Have fun and happy coding!