development:ohdsi_github_projects_v2
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| development:ohdsi_github_projects_v2 [2016/10/18 18:53] – created chrisknoll | development:ohdsi_github_projects_v2 [2017/02/02 14:41] (current) – chrisknoll | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | OHDSI open-source development best practices (DRAFT) | + | ===== Github Contributor Best Practices ===== |
| Contributors: | Contributors: | ||
| Line 13: | Line 13: | ||
| http:// | http:// | ||
| + | |||
| + | ==== Contributing code ==== | ||
| + | If you decide that you'd like to contribute code to OHDSI, the following sections will provide you with approaches for making contributions. Throughout this section, we'll refer to two distinct groups: **internal collaborators** and **external collaborators**. The difference between these groups is centered around their access to the repository. **Internal Collaborators** have rights to merge and push their changes directly into the repository while **external collaborators** do not. External collaborators must fork a repository in order to do their work and submit a pull request. This [[http:// | ||
| + | |||
| + | Whether you are an internal or external collaborator, | ||
| + | |||
| + | ==== Code Management ==== | ||
| + | |||
| + | The following section is described how to work with source code in a Git repository. It provides a general overview of using Git and explains how to provide code contributions. Subsequently, | ||
| + | |||
| + | === Forking and Cloning === | ||
| + | |||
| + | In order to begin working on OHDSI code, you will either need to clone a repository (repo) either directly from OHDSI or from a fork of an OHDSI repo. If you do not have permissions to push changes into a repo (which is usually the case when you are an external collaborator), | ||
| + | |||
| + | === Working with a repository === | ||
| + | |||
| + | Once you know the repository you want to work on (either a fork or directly in the OHDSI repo), you will then need to clone it locally. Create a directory that you'd like to use to store your Git code (i.e. C:\Git). Then using the Git command line, navigate to the directory you created and clone a repository using the following command: | ||
| + | |||
| + | < | ||
| + | $ cd C:\git | ||
| + | $ git clone " | ||
| + | </ | ||
| + | |||
| + | This will create a directory {RepoName} under the directory you executed the git command (in this example, C: | ||
| + | |||
| + | An additional step for **forked repositories**: | ||
| + | |||
| + | < | ||
| + | $ git remote add upstream https:// | ||
| + | </ | ||
| + | |||
| + | We will describe this ' | ||
| + | |||
| + | === Viewing the repository history === | ||
| + | |||
| + | To see the history in the repo, you can use any of the following commands: | ||
| + | |||
| + | < | ||
| + | $ git log | ||
| + | $ git log --graph | ||
| + | $ gitk | ||
| + | </ | ||
| + | |||
| + | gitk will launch a UI that let's you see the commits in a visual graph and is the recommended commit history viewer. | ||
| + | |||
| + | If everything looks good, then congratulations! | ||
| + | |||
| + | |||
| + | === Working in branches === | ||
| + | |||
| + | When you want to add a new feature or contribute a fix, you will always start by creating a branch. | ||
| + | |||
| + | < | ||
| + | $ git branch | ||
| + | </ | ||
| + | |||
| + | You will see something similar to the following: | ||
| + | |||
| + | < | ||
| + | $ git branch | ||
| + | Branch 1 | ||
| + | Branch 2 | ||
| + | (*) master | ||
| + | </ | ||
| + | |||
| + | The asterisk will provide you with an indicator of your current branch which in this case is " | ||
| + | |||
| + | Let's start by creating a new branch for our work by issuing the command: | ||
| + | |||
| + | < | ||
| + | $ git checkout -b " | ||
| + | </ | ||
| + | |||
| + | You'll then see the following: | ||
| + | |||
| + | < | ||
| + | $ git checkout -b " | ||
| + | Switched to a new branch ' | ||
| + | </ | ||
| + | |||
| + | Git has created a new branch called " | ||
| + | |||
| + | < | ||
| + | $ git branch | ||
| + | Branch 1 | ||
| + | Branch 2 | ||
| + | master | ||
| + | (*) new-feature-branch | ||
| + | </ | ||
| + | |||
| + | Now you can begin working by adding new commits to the repository. The new commits will be only visible in the ' | ||
| + | |||
| + | === Committing changes === | ||
| + | |||
| + | As you develop your code, you will be changing files and adding them to the repository by using the " | ||
| + | |||
| + | < | ||
| + | $ git commit -a -m "< | ||
| + | </ | ||
| + | |||
| + | This is a good option if you know all your changed files relates to a single feature or bug-fix. | ||
| + | |||
| + | < | ||
| + | $ git add {file 1} | ||
| + | $ git add {file 2} | ||
| + | $ git add {file 3} | ||
| + | $ git commit -m "Fixes #125" | ||
| + | $ git add {file 4} | ||
| + | $ git add {file 5} | ||
| + | $ git add {file 6} | ||
| + | $ git commit -m "Fixes #128" | ||
| + | </ | ||
| + | |||
| + | The above adds file 1, file 2 and file 3 into one commit, and file 4, file 5 and file 6 into a second commit, each commit having a different message. | ||
| + | |||
| + | |||
| + | === Pushing Changes and Pull Requests === | ||
| + | |||
| + | Once you have completed your local changes, you will want to submit them for inclusion in the main repository. | ||
| + | |||
| + | First, you will need to " | ||
| + | |||
| + | < | ||
| + | $ git push -v origin --all | ||
| + | </ | ||
| + | |||
| + | This will make your branch available on GitHub as a source for a pull request. | ||
| + | |||
| + | GitHub has an [[https:// | ||
| + | |||
| + | If you wanted to contribute your commits from ' | ||
| + | |||
| + | === Fetching and Merging changes === | ||
| + | |||
| + | At some point during your feature branch development, | ||
| + | |||
| + | Before you rebase, however, you must ensure that you have the latest version of master from the remote repository. | ||
| + | |||
| + | < | ||
| + | $ git fetch origin | ||
| + | remote: Counting objects: 72, done. | ||
| + | emote: Total 72 (delta 24), reused 24 (delta 24), pack-reused 48 | ||
| + | Unpacking objects: 100% (72/72), done. | ||
| + | From https:// | ||
| + | | ||
| + | </ | ||
| + | |||
| + | In the above example, the ' | ||
| + | |||
| + | **Note:** This command returns no output if nothing has changed on the remote. | ||
| + | |||
| + | Once the remote branches (including master) have been fetched, you can then rebase your feature branch on top of the latest tip of master. | ||
| + | |||
| + | < | ||
| + | $ git rebase origin/ | ||
| + | </ | ||
| + | |||
| + | **Note:** the new-feature-branch parameter is not required if the active branch is ' | ||
| + | |||
| + | Visually, the rebase performed like this: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Now that the new-feature-branch has been moved to the tip of origin/ | ||
| + | |||
| + | === Working inside a Shared Branch === | ||
| + | |||
| + | For private, single-developer branches, rebasing is the cleanest method of incorporating upstream changes into your branch. | ||
| + | |||
| + | Developer 1 creates the new feature branch: | ||
| + | < | ||
| + | $ git checkout -b shared-feature | ||
| + | Switched to a new branch ' | ||
| + | ...hack hack hack.... | ||
| + | $ git add . | ||
| + | $ git commit -m "my new feature" | ||
| + | </ | ||
| + | |||
| + | From here, Developer 2 may want to get involved with this feature, so Developer 1 pushes the branch, and Developer 2 pulls and checks out the branch. | ||
| + | |||
| + | Developer 1 pushes using the -u flag so that the remote branch will be tracked: | ||
| + | < | ||
| + | $ git push -u origin | ||
| + | </ | ||
| + | |||
| + | Developer 2 fetches the new branch: | ||
| + | < | ||
| + | $ git fetch origin | ||
| + | * [new branch] | ||
| + | $ git checkout -b shared-feature origin/ | ||
| + | </ | ||
| + | |||
| + | Now Developer 2 is working inside a local branch " | ||
| + | |||
| + | Developer 1 and Developer 2 are now sharing this branch, and will use git pull and git push to merge changes into the shared-feature branch. | ||
| + | |||
| + | Either Developer 1 or Developer 2 can perform this, but only one of them needs to do this to create the pull request branch: | ||
| + | |||
| + | < | ||
| + | $ git fetch origin | ||
| + | $ git checkout shared-feature | ||
| + | $ git checkout -b shared-feature-pr # creating a new branch at the tip of the shared-feature branch; active branch is now " | ||
| + | $ git rebase origin/ | ||
| + | $ git push origin | ||
| + | </ | ||
| + | |||
| + | The shared-feature-pr will contain a copy of the commits from shared-feature branch, but applied to the top of the master branch. After pushing, the branch will be available on github as a **head** of the pull request. | ||
| + | |||
| + | === Syncing an upstream Fork === | ||
| + | |||
| + | In most cases, the repository you're contributing to is a fork of an OHDSI repository. | ||
| + | |||
| + | < | ||
| + | $ git fetch upstream # will fetch latest commits from the upstream repository | ||
| + | $ git checkout master | ||
| + | $ git merge upstream/ | ||
| + | </ | ||
| + | |||
| + | We force a --ff-only because the only commits that should be applied to your forked repository' | ||
| + | |||
| + | ==== Conclusion ===== | ||
| + | |||
| + | In summary, the main mode of contributing to OHDSI repositories is branching from the master, and submitting Pull Requests. | ||
| + | |||
| + | If there' | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
development/ohdsi_github_projects_v2.1476816817.txt.gz · Last modified: by chrisknoll
