Maven Git Convention

This document describes how developers should use Git, our SCM.

Git migration

ETA of git migration is here: https://cwiki.apache.org/confluence/display/MAVEN/Git+Migration

Git Configuration

TODO

Commit Message Template

Commits should be focused on one issue at a time, because that makes it easier for others to review the commit.

A commit message should use this template:

[ISSUE-1] <<Summary field from JIRA>>
Submitted by: <<Name of non-committer>>

o Comments

Where:

  • ISSUE-1 can be omitted if there was no relevant JIRA issue, though you are strongly encouraged to create one for significant changes.
  • Submitted by only needs to be specified when a patch is being applied for a non-committer.
  • Comments some optional words about the solution.

eg:

[MNG-1456] Added the foo to the bar
Submitted by: Baz Bazman

o Applied without change

Apply User Patch

By default, the committer should apply the patch without any major modifications. In a second step, the committer could apply any changes as usual.

Edit Commit Message

to edit last commit comment:

$ git commit --amend -m "new comment"

Workflow

Workflow for svn folks is something like :

 $ git pull
 $ hack hack hack
 $ git push
 // fails, because someone else has already pushed to master
 $ git pull
 // this creates some merges
 $ git push

A more quiet workflow :

$ git pull
$ hack hack hack
$ git push
// fails, because someone else has already pushed to master
$ git fetch
// this moves 'origin/master'
$ git rebase origin/master
// this reapplies your local changes on top of origin/master
$ git push

Other useful Git commands while developing

If you've done a chunk of work and you would like ditch your changes and start from scratch use this command to revert to the original checkout:

$ git checkout .

TODO .gitignore

power-git checkout

This checkout is typical for highly experienced git users, and may serve as inspiration for others; as usual the best way to learn is by doing. Sample shown for maven-surefire

Go to https://github.com/apache/maven-surefire and fork surefire to your own github account.

Starting with nothing (no existing clone)

git clone https://github.com/<youraccount>/maven-surefire.git
git remote add apache https://git-wip-us.apache.org/repos/asf/maven-surefire.git
git remote add asfgithub https://github.com/apache/maven-surefire.git
git config --add remote.asfgithub.fetch "+refs/pull/*/head:refs/remotes/asfgithub/pr/*"
git fetch --all

(You may consider adding --global to the git config statement above to always fetch pull requests for any remote named "asfgithub")

In this setup, running "git push" will normally push to your personal github account. Furthermore, all pull requests from github are also fetched to your local clone, use

gitk --all

to try to make some sense of it all. This is an important command to understand! (gitk may need to be installed additionally)

gitk also has a quite excellent context menu that is far more context sensitive than most people realize at first impression. Right-clicking on a commit in a github pull-request will allow you to cherry-pick straight in the gui.

If you're working on the master branch, you can do stuff like this:

git push # your github account
git push apache # the authorative apache repo

Using your github account as a storage for half-finished work is excellent if you switch between multiple computers, always push to github before leaving your current computer and start by pulling at the next computer.

To merge a pull request

git merge pr/10 # merge pull request number 10 from asf@github into master
git push apache # upload to apache

Or if you're comfortable with rebasing;

git checkout pr/10
git rebase apache/master
git push apache