MIT 6.S194 | Open Source Software Project Lab  

Creating and Using a Personal Git Repo over SSH

For this tutorial, we'll be using your Athena account to host a git repository, but any system that you have access to over ssh will do. (For example, `login.csail.mit.edu`).

First, pair up with someone from a different group project than you.

1. Creating a Git Repository

Git doesn't have separate notions of "central repository" and "client checkout" like centralized version control systems. All participants in the ecosystem have copies of a full working repository. But there are several ways to create a repository, including:

1. Create from Scratch

Initialize an empty git workspace, with the database in the `.git` folder.

Use when you are creating a repository on your local system.

2. Create from Scratch
bare mode

Initializes an empty git database

Use when you are creating a repository on a server to act as a remote.

3. Clone Copies an existing repository.
We'll be using the second and third method in this exercise.
  1. Log in to Athena using the web interface or ssh, whichever you prefer.
  2. Create a directory called git to hold your repositories. (The name of this directory isn't important. You can call it rutabega if you want.) And change directories there.
        eob@dr-wily:~$ mkdir git
        eob@dr-wily:~$ cd git
  3. Next we'll create a directory for our new repository. Because we don't intend to actually develop out of this directory, we'll create a bare repository. The convention for creating bare repositories is to append `.git` to their name, as in `REPONAME.git`. Let's call the repository filebox.git. Change directories into it after you've created it.
        eob@dr-wily:~/git$ mkdir filebox.git
        eob@dr-wily:~/git$ cd filebox.git/
  4. Finally, create the repository!
      git init --bare
  5. That's it, you've just created a bare repository (the second method in the table above).

2. What hath git wroght?

That git command just dumped a brand new, shiny git database straight into your `~/git/filebox.git` directory in Athena.

eob@dr-wily:~/git/filebox.git$ ls -l
total 13
drwxr-xr-x 2 eob mit 2048 Feb 11 19:24 branches
-rw-r--r-- 1 eob mit   66 Feb 11 19:24 config
-rw-r--r-- 1 eob mit   73 Feb 11 19:24 description
-rw-r--r-- 1 eob mit   23 Feb 11 19:24 HEAD
drwxr-xr-x 2 eob mit 2048 Feb 11 19:24 hooks
drwxr-xr-x 2 eob mit 2048 Feb 11 19:24 info
drwxr-xr-x 4 eob mit 2048 Feb 11 19:24 objects
drwxr-xr-x 4 eob mit 2048 Feb 11 19:24 refs

Take a minute and poke around. This is an empty repository, so there isn't much to see, but you can start to get a feel for what, exactly, git does behind the scenes. For instance, you infer from the directory listing where git stores your branches. Take a look inside the `HEAD` file and you'll see that it's essentially a pointer into elsewhere in this directory structure. The git "database" is really just a bunch of carefully organized files!

3. Putting it to use

Back on your own machine (not Athena), let's clone this repo. Open up a terminal on your computer and change to a directory that you don't mind messing around in.

Now, assuming that you've named everything the same as I have, issue the following command (you'll have to change the username:

localhost:Code eob$ git clone eob@linerva.mit.edu:~/git/filebox.git
Cloning into 'filebox'...
Password: 
warning: You appear to have cloned an empty repository.
localhost:Code eob$ 
In Class: Discuss git URLs. Show scp.
  • SSH: user@server:/path.git
  • http(s)://domain/path/to/repo.git
  • git://github.com/schacon/grit.git

You get a warning because you've cloned an empty repository, but that's ok.

  1. Try creating a file, `index.html` and filling it with some content:
      <html>
      <head></head>
      <body>
      <h1>Hello, World!</h1>
      </body>
      </html>
  2. Then check that in and push it up to the repository.
      git add index.html
      git commit -m "Initial checkin"
      git push origin master