(taken from the great guide by the Apache Mahut group - https://mahout.apache.org/developers/github.html)
There are several ways to setup Git for committers and contributors. Contributors can safely setup Git any way they choose but committers should take extra care since they can push new commits to the master at Apache and various policies there make backing out mistakes problematic. Therefore all but very small changes should go through a PR, even for committers. To keep the commit history clean take note of the use of --squash below when merging into apache/master.
Start by forking https://github.com/apache/lucenenet on github. For every contribution you are about to make, you should create a branch (tracking master!) with some descriptive name, and send us a Pull Request once it is ready to be reviewed and merged.
And please git rebase <https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase> when pulling from origin/master instead of merging :)
Git setup for Committers
This describes setup for one local repo and two remotes. It allows you to push the code on your machine to either your Github repo or to git-wip-us.apache.org. You will want to fork github's apache/lucenenet to your own account on github, this will enable Pull Requests of your own. Cloning this fork locally will set up "origin" to point to your remote fork on github as the default remote. So if you perform "git push origin master" it will go to github.
To attach to the apache git repo do the following:
git remote add apache https://git-wip-us.apache.org/repos/asf/lucenenet.git
To check your remote setup
git remote -v
you should see something like this:
origin https://github.com/your-github-id/lucenenet.git (fetch) origin https://github.com/your-github-id/lucenenet.git (push) apache https://git-wip-us.apache.org/repos/asf/lucenenet.git (fetch) apache https://git-wip-us.apache.org/repos/asf/lucenenet.git (push)
Now if you want to experiment with a branch everything, by default, points to your github account because 'origin' is default. You can work as normal using only github until you are ready to merge with the apache remote. Some conventions will integrate with Apache Jira ticket numbers.
git checkout -b lucenenet-xxxx #xxxx typically is a Jira ticket number #do some work on the branch git commit -a -m "doing some work" git push origin lucenenet-xxxx # notice pushing to **origin** not **apache**
Once you are ready to commit to the apache remote you can merge and push them directly or better yet create a PR.
How to create a PR (committers)
Push your branch to Github:
git checkout lucenenet-xxxx git push origin lucenenet-xxxx
Go to your lucenenet-xxxx branch on Github. Since you forked it from Github's apache/lucenenet it will default any PR to go to apache/master.
- Click the green "Compare, review, and create pull request" button.
- You can edit the to and from for the PR if it isn't correct. The "base fork" should be apache/lucenenet unless you are collaborating separately with one of the committers on the list. The "base" will be master. Don't submit a PR to one of the other branches unless you know what you are doing. The "head fork" will be your forked repo and the "compare" will be your lucenenet-xxxx branch.
- Click the "Create pull request" button and name the request "LUCENENET-XXXX" all caps. This will connect the comments of the PR to the mailing list and Jira comments.
- From now on the PR lives on github's apache/lucenenet. You use the commenting UI there.
- If you are looking for a review or sharing with someone else say so in the comments but don't worry about automated merging of your PR--you will have to do that later. The PR is tied to your branch so you can respond to comments, make fixes, and commit them from your local repo. They will appear on the PR page and be mirrored to Jira and the mailing list.
When you are satisfied and want to push it to Apache's remote repo proceed with Merging a PR
How to create a PR (contributors)
Create pull requests: .
Pull requests are made to apache/lucenenet repository on Github. In the Github UI you should pick the master branch to target the PR as described for committers. This will be reviewed and commented on so the merge is not automatic. This can be used for discussing a contributions in progress.
Merging a PR (yours or contributors)
Start with reading  (merging locally).
Remember that pull requests are equivalent to a remote github branch with potentially a multitude of commits. In this case it is recommended to squash remote commit history to have one commit per issue, rather than merging in a multitude of contributor's commits. In order to do that, as well as close the PR at the same time, it is recommended to use squash commits.
Merging pull requests are equivalent to a "pull" of a contributor's branch:
git checkout master # switch to local master branch git pull apache master # fast-forward to current remote HEAD git pull --squash https://github.com/cuser/lucenenet cbranch # merge to master
--squash ensures all PR history is squashed into single commit, and allows committer to use his/her own message. Read git help for merge or pull for more information about
--squash option. In this example we assume that the contributor's Github handle is "cuser" and the PR branch name is "cbranch". Next, resolve conflicts, if any, or ask a contributor to rebase on top of master, if PR went out of sync.
If you are ready to merge your own (committer's) PR you probably only need to merge (not pull), since you have a local copy that you've been working on. This is the branch that you used to create the PR.
git checkout master # switch to local master branch git pull apache master # fast-forward to current remote HEAD git merge --squash lucenenet-xxxx
Remember to run regular patch checks, build with tests enabled, and change CHANGELOG.
If everything is fine, you now can commit the squashed request along the lines
git commit -a -m "LUCENENET-XXXX description (cuser via your-apache-id) closes apache/lucenenet#ZZ"
LUCENENET-XXXX is all caps and where
ZZ is the pull request number on apache/lucenenet repository. Including "closes apache/lucenenet#ZZ" will close the PR automatically. More information is found here .
Next, push to git-wip-us.a.o:
push apache master
(this will require Apache handle credentials).
The PR, once pushed, will get mirrored to github. To update your github version push there too:
push origin master
Note on squashing: Since squash discards remote branch history, repeated PRs from the same remote branch are difficult for merging. The workflow implies that every new PR starts with a new rebased branch. This is more important for contributors to know, rather than for committers, because if new PR is not mergeable, github would warn to begin with. Anyway, watch for dupe PRs (based on same source branches). This is a bad practice.
Closing a PR without committing (for committers)
When we want to reject a PR (close without committing), we can just issue an empty commit on master's HEAD without merging the PR:
git commit --allow-empty -m "closes apache/lucenenet#ZZ *Won't fix*" git push apache master
that should close PR
ZZ on github mirror without merging and any code modifications in the master repository.
Apache/github integration features
Read . Comments and PRs with Lucene.Net issue handles should post to mailing lists and Jira. Lucene.Net issue handles must in the form LUCENENET-YYYYY (all capitals). Usually it makes sense to file a jira issue first, and then create a PR with description
In this case all subsequent comments will automatically be copied to jira without having to mention jira issue explicitly in each comment of the PR.