Git Workshop

Eric Rochester

Scholars’ Lab

March 19, 2014

What is It?

Why Use it?

Git’s Worldview

Creating a Project

Changing a Project

Sharing a Project

What is It?

Distributed

Version

Control

System

Why Use It?

File Backup


$ ls

Paper.doc
Paper-aug-30-300.doc
Paper-aug-4-700.doc
Paper-aug-4-800.doc
Paper-jul-31-730.doc
Paper-sept-1-830.doc

$ cp Paper.doc Paper-nov-8-400.doc

Directory Backup


$ ls

website/
website-aug-30-300.zip
website-aug-4-700.zip
website-aug-4-800.zip

$ zip -r website website-nov-8-400.doc

What’s Wrong with this Picture?

  • When did I remove that section?
  • What was I working on Aug 4?
  • Was that 8:00 AM or PM?
  • When did I change the stylesheet?
  • How do I collaborate?
  • If I send someone a ZIP, how do I get the changes back out? What if we’ve both changed something?

How Does Git Fix it?

  • Commits and commit messages
  • History
  • Branches

Git Doesn’t Do

  • Website hosting
  • Build system
  • Archiving or backup

How Does Git See the World?

Working Directory

Staging

The Repository

Remotes

Getting Ready

Who Am I?


$ git config --global user.name "Eric Rochester"
$ git config --global user.email "erochest@virginia.edu"

Creating a Project


$ mkdir new-site

$ cd new-site

$ git init

Initialized empty Git repository in /Users/err8n/tmp/new-site/.git/


$ touch index.html

Edit index.html


$ git status

# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       index.html
nothing added to commit but untracked files present (use "git add" to track)


$ git add index.html

$ git status

# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   index.html
#


$ git commit -m "initial import"

[master (root-commit) 2c49bf0] initial import
 1 file changed, 15 insertions(+)
  create mode 100644 index.html

$ git status

# On branch master
nothing to commit, working directory clean


$ git log

commit 2c49bf0977c74ce232cb52fcb8d129e32ee94f28
Author: Eric Rochester <erochest@virginia.edu>
Date:   Thu Nov 7 15:24:46 2013 -0500

    initial import

Changing a Project

Edit index.html again.


$ touch style.css

Edit style.css


$ git status

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   index.html
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       style.css
no changes added to commit (use "git add" and/or "git commit -a")


$ git diff

diff --git a/index.html b/index.html
index 8a5f865..6f7d64e 100644
--- a/index.html
+++ b/index.html
@@ -3,6 +3,7 @@
 <head>
     <title></title>
     <meta charset="utf-8" />
+    <link rel="stylesheet" href="style.css" type="text/css">
 </head>
 <body>
     <header>


$ git add index.html style.css

$ git status

 # On branch master
 # Changes to be committed:
 #   (use "git reset HEAD <file>..." to unstage)
 #
 #       modified:   index.html
 #       new file:   style.css
 #


$ git commit -m "A little bit stylish."

[master 740343e] A little bit stylish.
 2 files changed, 4 insertions(+)
  create mode 100644 style.css


$ git status

# On branch master
nothing to commit, working directory clean


$ git log

commit 740343ec54003a3c70ea2faef961ee22b4c0e2ff
Author: Eric Rochester <erochest@virginia.edu>
Date:   Thu Nov 7 16:57:05 2013 -0500

     A little bit stylish.

commit 2c49bf0977c74ce232cb52fcb8d129e32ee94f28
Author: Eric Rochester <erochest@virginia.edu>
Date:   Thu Nov 7 15:24:46 2013 -0500

      initial import

Sharing a Project

Uphill Both Ways

  • Running your own server.
  • Emailing diffs.

Github

The unholy spawn of Facebook and git.

Let’s get an account!

https://github.com

Plays Well With Others

  • Organizations
  • Collaborators
  • Forking
  • Pull Requests

Remote Repositories

Create a new repository on Github.

Let’s Do That Then!


$ git remote add origin git@github.com:erochest/new-site.git
$ git push -u origin master

Refresh

Github

The Clone Wars

MOAR!

Branches

Workflows

Forking

More Resources

Git

http://git-scm.com/

Github

https://github.com/

A Great Cheatsheet

http://rogerdudler.github.io/git-guide/files/git_cheat_sheet.pdf

Scholars’ Lab Resources