Code generators and git-rebase

The classic example of using git-rebase is when a developer is working on their own branch while commits are made to the master branch, then the developer wants to sync up with the master branch, maybe as a precursor to merging the changes back into the master branch. Git’s rebase handles this elegantly by pushing the changes on the developers branch, moving the point where the developers branch is forked from the master branch, then apply the saved changes to the new developers branch.

Classic Rebasing
Classic rebase

For completeness, the command is:

git rebase master developer_branch

Cool.

But for grins, let’s turn the problem around. Let’s say that you use a code generator to jump start your project. What usually happens is the code generators are only used until you invest time and effort into changing the code. Wouldn’t it be nice to be able to use the code generators through out the development cycle?

The easiest way is to create a ‘generated’ branch for the code generators to use then rebase to master.

Generator Rebasing
Generator Rebasing

In this case the command would be:

git rebase generated master

While you will have to manually refactor any name changes on the master branch introduced by the generated branch, you now have the option of using the generators over the life of the project.

Have fun,
Roy

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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