Licensed under the Creative Commons attribution-noncommercial license, http://creativecommons.org/licenses/by-nc/3.0/. Please share and remix noncommercially, mentioning its origin.
As discussed in class, git is currently the dominant tool for managing, developing and sharing code within the computational sciences and industry. Github is the largest git-based internet repository, but others (such as bitbucket) also use git, and it can be useful to use git to build a local repository on your own computer.
Our goals are
Learn some ways to think about what a git repository is and how it works.
Practice going through the process of downloading a github repository, editing it, and uploading the changes.
This introduction uses material from Karl Broman’s practical and minimal git/github tutorial (kbroman.org/github_tutorial). A deeper, more technical tutorial is www.atlassian.com/git/tutorials.
Git was developed for Unix-like systems (Linux and Mac). According to Wikpedia’s article on git
“The Microsoft Windows ‘port’ of Git is primarily a Linux emulation framework that hosts the Linux version. […] Currently there is no native port of Git for Windows.”
Get an account on github.
If you are on a Mac or Linux machine, git will likely be installed already. Otherwise, you can download and install it from git-scm.com/downloads.
Set up your local git installation with your user name and email. Open a terminal and type:
$ git config --global user.name "Your name here"
$ git config --global user.email "your_email@example.com"
(Don’t type the $; that just indicates that you’re doing this at the command line.)
repository. A representation of the current state of a collection of files, and its entire history of modifications.
commit. A commit is a change to one or many of the files in repository. The repository therefore consists of a directed graph of all previous commits.
branch. Multiple versions of the collection of files can exist simultaneously in the repository. These versions are called branches. Branches may represent new functionality, or a bug fix, or different versions of the code with slightly different goals.
Branches have names. A special name called master is reserved for the main development branch.
Branches can be created, deleted or merged.
Each new commit is assigned to a branch.
We now have the pieces in place to visualize the graph of a git repository. [Picture credit: hades.github.io]
Take some time to identify the commits, branching events, and merging events on the graph.
git clone git@github.com:ionides/810f15
You now have a local copy of the Stats 810 class materials.
The local repository remembers the address of the remote repository it was cloned from.
[ionides@feller 810f15]$ git pull
Already up-to-date.
If you tell me your github username, I could in principle add you as a developer of the ionides/810f15
github repository. Then you can commit changes directly.
However, here, let’s practice something a bit more fancy. We will follow a standard workflow for proposing a change to someone else’s github repository.
Forking is making your own github copy of a repository. A pull request is a way to ask the owner of the repository to pull your changes back into their version. The following steps guide you through a test example.
Go to ionides/810f15
on github, for example by searching for 810f15
.
Click fork
at the top right-hand corner, and follow instructions to add a forked copy to your own github account. It should now show up in your account as my_username/810f15
.
Clone a local copy of the forked repository to your machine, e.g.,
git clone git@github.com:my_username/810f15
Move to the 810f15
directory and edit the file sign_here.html
to add your own name.
It can be helpful to type
git status
regularly to check on the current state of the repository.
810f15
,git add sign_here.html
git commit -m "sign up for my_name"
and see how the git status
has changed. Another useful command for checking on the recent action in the repository is
git log
810f15
on github:git push
my_username/810f15
fork, click New pull request
and follow instructions. When you have successfully placed your pull request, the owner of the forked repository (me) will be notifed. I will then pull the modifications from your fork into ionides/810f15
.