Using git (Swarthmore GitHub Enterprise)

If you haven't already done so, make sure you complete the one-time configuration steps before proceeding.

Accessing Swarthmore GitHub

The web address is https://github.swarthmore.edu. You should be able to log in with your typical Swarthmore credentials (the same username / password you use for email). Upon logging in, you should see a welcome page that lists the repositories you currently own.

For CS 31, we'll be using a feature of GitHub called "organizations", which allows us to control everything for the course. The organization this semester is named CS31-s16. From the main GitHub page, you can select the organization you want to use, or you can jump directly to the CS31-s16 organization.

On the organization page, you should see a list of repositories that you can access. The repositories will be named according to what they contain and which users can access them. For example, suppose two teammates (Sterling Archer, sarcher1, and Lana Kane, lkane1) are working together. When Lana accesses the organization, she would expect to see:

Cloning a local copy of the repository

With git, you and your partner both create a local copy ("clone") of the shared repository, make and commit changes locally, and push the changes back to GitHub, where your partner can retrieve them.

Click on a repository, and it'll take you to a page that lists its contents (and many other useful things). One the lower right hand side, you'll see some text that says "You can clone with HTTPS, SSH, or Subversion". Click the "SSH" link. This will give you a link that you can use to clone. Let's first enter our cs31 directory and make the clone there:

    cd
    cd cs31/labs

From here, you can use git clone [URL] to locally clone the repository, where [URL] is the SSH URL given to you by GitHub. For example, if Lana were cloning, she might use: "git clone git@github.swarthmore.edu:CS31-s16/Lab1-lkane1-sarcher1.git". You can now cd into your repository directory and access the files there.

If you get authentication errors, make sure you've uploaded an SSH key to your GitHub account. (See: one-time configuration steps)

Using your shared repo

At this point, you now have a master git repository for your project that only you, your partners, and graders/instructors can access. All changes, additions, deletions, to this project can be done with git commands that will push and pull changes from this remote master copy.

You and your partner will work in your local private copies of the repo. You can add and commit changes to your private copy as you go, and choose when to push your change to the remote master repo. Once you push changes, your instructor or partner can then pull from the remote master into their copy.

An example of a sequence of common git commands:

 # check the status of your repo
 $ git status

 # see the changes to the file (compared to your last local commit):
 $ git diff blah.c

 # add a new file to the repo on the next commit:
 $ cp ~/private/foo.c .
 $ git add foo.c
 # or add new changes to an existing repo file to the next commit:  
 $ vi blah.c      # edit with your favorite editor
 $ git add blah.c  

 # commit your changes (adds and deletes) to your local repository:
 $ git commit

 # push committed changes from your local to the remote master repository
 #  note: the first time you push, you may need to do:
 #        git push origin master
 $ git push

 # your partner can now pull your changes from the remote into their local:
 $ git pull

Some notes about these commands:

.gitignore

It is useful to add a .gitignore file to your repo. It tells git automatically ignore adding certain files or file types to the repo, such as .o and executable files and editor backup files (like vim .swp files). This way if you do a git add git doesn't try to add all kinds of kooky files to the repo. Here is an example .gitignore file for a C program that build an executable file named myprog:
*.o
myprog
*.swp
You add a .gitignore file to a git repo just like you add any other file:
git add .gitignore
git commit
git push

Common commands:

git help    # list common git commands  git help --all lists all commands
git add     # add changes or new files to the next commit 
git rm      # remove a file at the next commit
git commit  # commit your changes to your local repository
git push    # push your committed changes to the remote master repository
            # (note: the first time you may have to do: push origin master
git pull    # pull changes pushed to remote master into your local copy 
            # (git will try to merge changes into your copy)
git mv      # move a repo file
git diff    # see a diff between a file(s) and latest commit (local repo)
git diff master origin/master  # diff between your copy and master's
git status  # see what has changed between your copy and the master version
git branch -a # see all the branches (likely only master)

git tools:

Troubleshooting

Links to git Resources


git documentation sections 1 and 2 in particular are very useful
git user's manual
Andy's git wiki page more complete coverage of common and advanced git feature
git cheatsheet
git magic a good source of information about more advanced and obscure git functionality