Example Git Workflows: Merging a Contributor via Pull
17 Apr 2008
Welcome to my series of articles providing example workflows for working with the Rails core Git repository. My first post is designed for Rails core committers and explains one way to deal with contributions that come in the form of a Git URL and a branch name.
Based on my interactions with the core, I’d deduced the following are common requirements when merging a contributor’s work, and modeled my example around them:
- Preserve history: don’t squash to a single commit
- Provide a paper trail of which core committer merged the contribution
- Add a
CHANGELOG
entry on top
First, a recommended configuration option. This will add a short summary of the changes a merge introduces to the commit message.
$ git config --global merge.summary true
On to the merge. The first thing we want to do is bring our master
branch up to date. The assumption here is that we don’t have any local
work done in master
: it’s a clean branch tracking the upstream, so
that git pull
will simply fast forward the latest changes.
$ git checkout master
$ git pull
Next, let’s pull in our contributor’s branch.
$ git pull --no-ff --no-commit git://github.com/someone/rails.git branch
We use --no-ff
to disallow fast forwarding, even if the
remote branch is up to date. This ensures there will always be a merge
commit, providing for the paper trail requirement mentioned earlier.
The --no-commit
option gives us a chance to alter the work
tree as part of the merge commit. Putting hefty changes here would be
confusing, but it is the perfect chance to make CHANGELOG
edits.
$ edit activesupport/CHANGELOG
$ git add activesupport/CHANGELOG
Once the CHANGELOG
is to your liking, we are ready to finalize it.
The commit message is already in place but feel free to replace it if it
doesn’t give a clear picture of what changed.
$ git commit
$ git push