Skip to content
This repository has been archived by the owner on Aug 23, 2021. It is now read-only.

Developer Bootstrap

MattNapsAlot edited this page Apr 29, 2012 · 1 revision

This page will contain basic info on how to contribute to this project.

Git branches

dev branch

During development, changes should be pushed into the dev branch. No test-breaking changes should be pushed to this branch.

master branch

The master branch is the mainline of the code. In general, the dev branch should only be merged into master upon release.

feature branches

It is common practice to start a new branch for each feature implementation. Creating a new branch is easy:

$ git checkout -b myFeature
$ git branch
  master
* myFeature

You can see that the active branch is now "myFeature".

Changes to this branch can be committed locally periodically.

$ git commit -am "my checkin comment"

One or more checkins can then be pushed to the remote repository. It will be automatically created the first time you push:

$ git push origin myFeature

Demonstration of the branch/merge workflow

Create a new branch for the feature that is being implemented. In this case it is the global variable store.

(dev)$ git checkout -b GlobalCache
Switched to a new branch 'GlobalCache'
(GlobalCache)$

After making the feature changes using a text editor, get the status

(GlobalCache)$ git status
# On branch GlobalCache
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   R/AllClasses.R
#	new file:   R/FileCache.R
#	new file:   R/GlobalCache.R
#	new file:   R/hasZip.R
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   R/AllGenerics.R
#	modified:   R/GlobalCache.R
#	modified:   R/hasZip.R
#	modified:   R/zzz.R

Stage the changes for commit

(GlobalCache)$ git add *
(GlobalCache)$ git status
# On branch GlobalCache
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   R/AllClasses.R
#	modified:   R/AllGenerics.R
#	new file:   R/FileCache.R
#	new file:   R/GlobalCache.R
#	new file:   R/hasZip.R
#	modified:   R/zzz.R

Commit the changes

(GlobalCache)$ git commit -am "implemented GlobalCache class. Added FileCache class."
[GlobalCache ba10a63] implemented GlobalCache class. Added FileCache class.
 6 files changed, 172 insertions(+), 26 deletions(-)
 create mode 100644 R/FileCache.R
 create mode 100644 R/GlobalCache.R
 create mode 100644 R/hasZip.R

Now change back to the dev branch and merge the GlobalCache branch

(GlobalCache)$ git checkout dev
Switched to branch 'dev'
(dev)$ git merge GlobalCache
Updating 03ef3c9..ba10a63
Fast-forward
 R/AllClasses.R  |    9 ++++
 R/AllGenerics.R |    7 +++
 R/FileCache.R   |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 R/GlobalCache.R |   31 +++++++++++++++
 R/hasZip.R      |    8 ++++
 R/zzz.R         |   32 +++-------------
 6 files changed, 172 insertions(+), 26 deletions(-)
 create mode 100644 R/FileCache.R
 create mode 100644 R/GlobalCache.R
 create mode 100644 R/hasZip.R

Check the status

(dev)$ git status
# On branch dev
# Your branch is ahead of 'origin/dev' by 1 commit.
#
nothing to commit (working directory clean)

The changes are ready to commit, so after running the unit tests in R, push the changes to the remote repository.

(dev)$ git push origin dev
Counting objects: 14, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 2.17 KiB, done.
Total 9 (delta 6), reused 0 (delta 0)
To [email protected]:Sage-Bionetworks/rSynapseClientRewrite.git
   03ef3c9..ba10a63  dev -> dev

Git tips and tricks

Follow this link for help on using Git. Below are some tips to get started.

.gitignore

Files that should be ignored by git can be added to a file named ".gitignore" in the root of the project directory, including the .gitignore file itself. Just put the filename in the file and git won't track it.

Cloning the repository

To download a complete copy of the remote repository you can use the clone command:

$ git clone [email protected]:Sage-Bionetworks/rSynapseClientRewrite.git
Cloning into rSynapseClientRewrite...
remote: Counting objects: 292, done.
remote: Compressing objects: 100% (215/215), done.
remote: Total 292 (delta 70), reused 292 (delta 70)
Receiving objects: 100% (292/292), 1.11 MiB | 700 KiB/s, done.
Resolving deltas: 100% (70/70), done.

Listing the available remote branches

You can list the branches by typing the following from the root directory of the repository:

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/master

Fetching a remote branch

Since we will be working in the "dev" branch, you will need to fetch it:

$ git fetch origin dev
From github.com:Sage-Bionetworks/rSynapseClientRewrite
 * branch            dev        -> FETCH_HEAD

You can then make the dev branch active:

$ git checkout dev
Branch dev set up to track remote branch dev from origin.
Switched to a new branch 'dev'

Changing the current branch

To change the active branch use the checkout command

$ git checkout myFeature
Switched to branch 'myFeature'

Committing changes locally

In Git, changes are committed locally:

$ git commit -am "This is my checkin comment"

Pushing changes to the remote repository

Changes don't exist on the remote repository until they are pushed:

$ git push

Modifying your shell to display the active branch

It's easy to get confused about which branch is set to active. Add the following to your ~/.bashrc so that your shell will display the active branch:

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

PS1="\u@\h:\W\$(parse_git_branch)$ "

NOTE: Click this link for instructions on further customizing your shell.