This page documents how to develop ITK using Git.
Note: Git is an extremely powerful version control tool that supports many different "workflows" for individual development and collaboration. Here we document procedures used by the ITK development community. In the interest of simplicity and brevity we do not provide an explanation of why we use this approach. Furthermore, this is not a Git tutorial. Please see our GitHelp guide for third-party documentation.
Before you begin, perform initial setup:
- Register for a GitHub account.
- Optionally download our one page PDF desk reference.
- Follow the download instructions to create a local ITK clone:
$ git clone https://github.com/InsightSoftwareConsortium/ITK
- Run the developer setup script
SetupForDevelopment.sh
to prepare your ITK work tree and create Git command aliases used below:
$ ./Utilities/SetupForDevelopment.sh
This script helps configure your GitHub fork remote, Git client-side hooks,
and useful Git aliases. The default Git remote names for your fork and
InsightSoftwareConsortium/ITK
are origin
and upstream
, respectively.
However, other remote names can be used. Note that ITK defines some useful
Git aliases, such as review-push
, pr
, pr-clean
, and prepush
, through
the setup-git-aliases
script for general Git tasks in ITK.
Visit the Pro Git: Setup resource in GitHelp for further information on setting up your local Git environment.
ITK development uses a branchy workflow based on topic branches. This corresponds to the Fork & Pull Model mentioned in the GitHub flow guide. Our collaboration workflow consists of three main steps:
- Local Development
- Code Review
- Integrate Changes
Update your local master
branch:
$ git checkout master
$ git pullall
All new work must be committed on topic branches. Name topics like you might name functions: concise but precise. A reader should have a general idea of the feature or fix to be developed given just the branch name.
To start a new topic branch:
$ git fetch upstream
For new development, start the topic from upstream/master
:
$ git checkout -b my-topic upstream/master
For release branch fixes, start the topic from upstream/release
:
$ git checkout -b my-topic upstream/release
(You may visit the Pro Git: Basic Branching resource in GitHelp for further information on working with branches.)
Edit files and create commits (repeat as needed). Add a prefix to your commit message (see below).
$ edit file1 file2 file3
(To add data follow these instructions.)
$ git add file1 file2 file3
$ git commit
(You may visit the Pro Git: Recording Changes resource in GitHelp for further information on making changes and committing snapshots.)
Note: If your change modifies any of the modules in the
Modules/ThirdParty
directory, please read our
UpdatingThirdParty guide.
Standard prefixes for ITK commit messages:
BUG:
Fix for runtime crash or incorrect resultCOMP:
Compiler error or warning fixDOC:
Documentation changeENH:
New functionalityPERF:
Performance improvementSTYLE:
No logic impact (indentation, comments)WIP:
Work In Progress not ready for merge
When a topic is ready for review and possible inclusion, share it by pushing to GitHub and opening a pull request on the InsightSoftwareConsortium/ITK upstream repository.
Checkout the topic if it is not your current branch:
$ git checkout my-topic
Check what commits will be pushed to GitHub for review:
$ git prepush
Push commits in your topic branch for review by the community:
$ git review-push --force
A URL will be provided in the terminal -- visit this url to review the topic and open a pull request.
Optionally, discuss the change by opening a topic on ITK's Discourse.
When a topic is submitted, it is tested across the three major platforms before being merged. After the topic has been merged, it is tested on many platforms and configurations on the nightly dashboard.
If tests fail on a submitted topic, see the Revise a Topic step on how to submit a revised version. After a topic is merged, please check the next day's nightly dashboard to ensure there are not any regressions. If there are any new warnings or errors, submit a follow-up patch as soon as possible.
Usually, a topic goes through several revisions in the review process. Once a topic is approved during GitHub review, proceed to the next step.
Checkout the topic if it is not your current branch:
$ git checkout my-topic
To revise the most recent commit on the topic edit files and add changes normally and then amend the commit:
$ git commit --amend
(You may visit the Pro Git: Changing the Last Commit resource in GitHelp for further information on revising and rewriting your commit history.)
To revise commits further back on the topic, say the 3
rd commit back:
$ git rebase -i HEAD~3
(Substitute the correct number of commits back, as low as 1
.)
Follow Git's interactive instructions.
Return to the Share a Topic step to share the revised topic.
(You may visit the Pro Git: Changing Multiple Commits resource in GitHelp for further information on changing multiple commits -i.e. not only the last one, but further back in your history-, and the Pro Git: Rebasing resource on taking all the changes that were committed on one branch and replaying them on another one.)
Only authorized developers with GitHub merge permissions execute this step.
After a feature topic has been reviewed and approved in GitHub, ITK maintainers will merge it into the upstream repository via the GitHub user interface.
(If the merge conflicts follow the printed instructions to resolve them.)
For bug fixes that are ready to be included in the next patch release, make a
comment on the pull request which states the topic should be merged to the
release
branch.
Here are the recommended steps to merge a topic to both release
and master
branches, assuming the topic branch is forked off the release
branch:
$ git checkout release
$ git merge --no-ff my-topic
$ git push upstream release
and do:
$ git checkout master
$ git merge --no-ff release
$ git push upstream master
to merge the release
branch back to master
.
After a topic has been merged upstream, delete your local branch for the topic.
Checkout and update the master
branch:
$ git checkout master
$ git pullall
Delete the local topic branch:
$ git branch -d my-topic
The branch -d
command works only when the topic branch has been correctly
merged. Use -D
instead of -d
to force the deletion of an unmerged topic
branch (warning: you could lose commits).