This document describes how developers should use Git. The Maven project is in the process of migrating some of its components from svn to git.
Information on the migration is here: https://cwiki.apache.org/confluence/display/MAVEN/Git+Migration
Apache git repositories are at <<git://git.apache.org>>. However, the ASF uses clones on github.com to make it easier for people to contribute changes via pull requests.
To contribute to a Maven component that is maintained in git, please follow these steps:
Committers may, of course, commit directly to the ASF repositories. For complex changes, you may find it valuable to make a pull request at github to make it easier to collaborate with others.
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:
[MNG-1456] Added the foo to the bar Submitted by: Baz Bazman o Applied without change
To keep the history of contributions clear, The committer should usually apply the patch without any major modifications, and then create his or her own commits for further modifications. However, committers should never commit code to a live branch which is not suitable to release. If a contribution requires significant work to make it useful, commit it to a branch, fix it up, and merge the branch.
If the user created a pull request, the committer is responsible for closing that pull request. You do this by adding a note to a commit message:
Closes #NNN.
where NNN is the number of the pull request.
$ git commit --amend -m "new comment"
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
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
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