Working with GitHub

Credit: The information on this site comes almost entirely from https://education.github.com/.

Git Overview

Git is an open-source, distributed version control software. Check out its wiki page for more information on why to use it and what it can do. Git was initially created by Linus Torvalds (but subsequently had many core developpers) for Linux.

GitHub is a company that implements a web-based version of git: it has a nice web interface and also a place for you to put your projects "into the cloud". GitHub offers all the functionality of git and adss some of its own (like wiki pages for each project, and social-networking-like features like feeds and followers). GitHub has 20+ million users, and it's becoming a virtual meeting place for software developpers, for sharing information and showcasing projects.

In a nutshell, a version control system lets you and your peers work and collaborate on projects, from anywhere. Initially you (or someone else) will create a remote master repository on github for your project. This master repository is hosted remotely, on github. You (and your partners, if any) will then clone (checkout) a private copy of the remote master repository on your local machine. You can clone several copies of the master repo in several locations, if you want. You can make changes to your local copy. When you are done, you stage these changes for commit, and then you push them to the master repository. Once your changes are pushed to the master repo, your partners can get them by "pulling" the changes from the master repo into their local repo. Git automatically merges the changes pulled form the master with the local changes in the local repo. Finally, git has a feature where it keeps a record of all changes, and any change can be recovered and reverted.

GitHub classroom

We will be using GitHub classroom. This is a layer on top of GitHub, that allows everyone in the class to clone private versions of the projects. To use it, you need to have a GitHub account. A free account will be fine; With a free account all your data and projects will be public, ie viewable by everyone. Your class projects will be private through the private class account that I've created for the class.

Initial Git setup

Before you starting using the Git command on the command line, you need to give it a basic configuration. This will tell Git who you are, making it easy for you and your partners to identify who committed code to your shared repository. Replace the email and name strings with your email address and name. If you have not run these commands, then the very first Git commit will fail and tell you to run them.

git config --global user.email "username@bowdoin.edu"
git config --global user.name "Your Name"
git config --global push.default simple

Working with GitHub

Assume someone gives you a link for a GitHib repository. For example, here is the repository which holds a Helloworld program:

https://github.com/lauratoma/helloworld.git

First, you'll clone the master repository. To do this you will go to the path where you want to place your local directory. Let's say you want it on your Desktop:

cd Desktop
The first time you clone, you'll probably want to create a folder called "algorithms":
mkdir algorithms
Then you'll go to that directory:
cd algorithms
And you'll clone:
git clone https://github.com/lauratoma/helloworld.git
Once cloned, the usual work cycle in Git is pull-edit-commit-push-repeat: Again, git push does not take file names as arguments. Git push will sync the master repo with the commited files in the local repo.

That's it! We'll push branching later (pardon the pun).


Last modified: Wed Feb 21 11:29:27 EST 2018