We’ve already gone over markdown and RStudio in class. You can download RStudio at RStudio homepage. You can learn more about markdown at Markdown Help via RStudio.

Git and Bitbucket

Git is used for version control. Bitbucket is a free, private repository for using version control and sharing code, files, etc. (Github does the same thing). You can download bitbucket at Bitbucket homepage.

  1. First download git.
  1. Create a new repository (repo).

create a new directory, open it and perform

git init

to create a new repo.

  1. checkout a repo

create a working copy of a local repository by running the command

git clone /path/to/repository

when using a remote server, your command will be

git clone username@host:/path/to/repository

  1. workflow: your _local _repo has three “trees” maintained by git. The first is the Working Directory, which holds the actual files. The second one is the Index which acts as a staging area and finally the Head, which points to the last commit you made.

picture of work_flow

  1. add and commit

You can propose changes (add it to the Index) using

git add <fileName>

This is the first step of the basic git workflow. To commit these changes (to the master directory) use

git commit -m "Commit <add helpful message>.

Now the file is committed to the HEAD but not in your remote repository yet.

  1. pushing changes

Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, execute

git push origin master

Note: Change master to whatever branch you want to push your changes to. Now you are able to push your changes to the selected remote server (bitbucket for example.)

  1. branching

Branches are used to develop features isolated from each other. The master branch is the “default” branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion.

picture of branch

Create a new branch named “feature_x” and switch to it using

git checkout -b feature_x

Switch back to the master branch

git checkout master

and delete the branch again

git branch -d feature_x

A branch is not available to others unless you push the branch to your remote repository

git push origin <branch>

  1. update and merge

To update your local repo to the newest commit, do

git pull

in your working directory to fetch and merge remote changes.

To merge another branch into your active branch (e.g. master), use

git merge <branch>

in both cases git tries to auto-merge changes. Unfortunately, this is not always possible and results in conflicts. You are responsible to merge those conflicts manually by editing the files shown by git. After changing, you need to mark them as merged with

git add

before merging changes, you can also preview them by using

git diff <source_branch> <target_branch>

Note that in order to often fix conflicts, you will need to do this using vim. To enter the vi environment, type vi Then follow the instructions to address why you are making a merge. To save and exit, press esc followed by :wq enter which will save the changes and take you back to the console. (This is possibly the most annoying and tedious process but once you have it down, it’s easy.)