Using Git
Check out the code to your machine
- On github.com, fork a project you want to work on (see tutorial: http://help.github.com/fork-a-repo).
- We will base this example on the "openmrs-core" project (the core OpenMRS application).
- Go to https://github.com/openmrs/openmrs-core
- Click "Fork" button in the upper right
Clone the fork to your local machine (replace "yourusername"):
git clone https://github.com/yourusername/openmrs-core.git
Go into the folder just created and set up the "upstream" remote so you can eventually pull changes from the main repository (see "Configure Remotes" on http://help.github.com/fork-a-repo):
git remote add upstream https://github.com/openmrs/openmrs-core.git
Fetch and track all branches on remote repositories.
git fetch --all
After you cloned the repository you can list available branches:
git branch -a
The currently checked out branch is highlighted with an asterisks. The master branch is the latest development branch (trunk was its counterpart in SVN).
Pull changes from the upstream remote:
git pull --rebase upstream master
The '--rebase' option reverts any of your commits which are not in upstream/master, then fast forwards your local branch to upstream/master and finally applies your commits on top of that. This allows you to avoid merge commits and keep the history linear, but must not be used if you want others to work with you on a branch in your fork.
Optional pro tip: To save some key hits we recommend to setup an alias for 'pull --rebase' by running
git config --global alias.up "pull --rebase"
From now on you will be able to use 'git up upstream master' instead of 'git pull --rebase upstream master'.
Push changes to your fork on github:
git push
This command pushes all your commits from all your tracked branches to your fork. If your fork has commits, which are not in your local repository, the branches containing these commits will not be pushed. You will need to pull on these branches first to have them pushed.
We do not advise you to work on master or maintenance branches of openmrs-core, but create topic branches instead. This way you will be able to send us pull requests to merge your code back to the main repository. See "Create Topic Branches" below, please take a look at our pull requests tips page.
See Maven wiki page for how to build, compile, etc.
Get the code in read-only mode (without intention of contributing)
This will check out the code for "openmrs-core" (the core OpenMRS application):
git clone https://github.com/openmrs/openmrs-core.git
Checkout out a new local branch based on your master and update it to the latest. The convention is to name the branch after the current ticket e.g. TRUNK-123.
Make sure you have committed any new files that are not under version control otherwise you will lose them when you run *git clean -df*
git checkout -b TRUNK-123 master git clean -df git pull --rebase upstream master
Push the branch to your fork. Treat it as a backup.
git push origin TRUNK-123
Pro tip! Git has tab completion here!
Work on your task
NOTE: If the ticket you are working on requires you to work off a development branch say 1.9.x, you will have to use the development branch name instead of master for the instructions in this section. E.g. instead of git pull --rebase upstream master you will run git pull --rebase upstream 1.9.x, where 1.9.x is the development branch you are coding off.
- Make changes in code.
Add changes to a commit (stage them). To see what files have changed.
git status
To stage all changed and new files.
git add -A
To pick only some files.
git add -i
You will see a summary of changed and new files. You need to choose '2' to mark files as updated. Now you need to pick files, which you want to mark as updated. You can specify them as a list 1, 2, 3, as a range 1-3, or simply * to select all. Confirm by hitting the enter key twice. If there are new (untracked) files, choose '4' and pick files the same way. Choose '7' to quit.
Commit changes.