Git it Together

Peter Eltgroth

Lead Technical Analyst
peter@eltgroth.net


Jeremy Heydman

Web Architect
jeremy.heydman@so.mnscu.edu

Why use a version control system?

Changing Requirements

This worked in the last release . . .

How can I solve this?

What is version control?

A system that:

  • records changes over time
  • allows you to revert versions
  • does comparisons across time
  • knows who changed what and when it was changed
  • About Version Control

    Local Version Control Systems

    Local Version Control

    Centralized Version Control Systems

    Centralized Version Control

    Distributed Version Control Systems

    Distributed Version Control

    Why Git?

    Design goals:

  • Speed
  • Simplicity (like other *nix tools)
  • Support for non-linear development
  • Fully distributed
  • Able to handle large projects
  • Short History

    How?

    Git takes a stream snapshots by doing a SHA-1 check-sum of everything before it is committed.

    Git Basics

    Ability to commit work offline

    And later syncronize with others

    Fast, flexible branching and merging

    Experiment with solutions, merge the best & delete the rest.

    Full Local History

    Fast comparisons over the complete life of the project

    Installation

    MacOS

    Since Mavericks (10.9) just type 'git' in a terminal.

    If you want/need a newer version downlaod it directly from git-scm, use Homebrew, or GitHub Desktop.

    Windows

    Download git for windows or GitHub Desktop.

    Linux

    Fedora:

    
    							$ sudo yum install git-all
    						

    Debian-based:

    
    							$ sudo apt-get install git-all
    						

    SourceTree

    My favorite GUI

    Git Basics

    The Three States

  • committed
  • modified
  • staged
  • Snipcademy Three States

    Command Line Help

    
    							$ git {optional-command-name} --help
    						

    Try Git

    Learn Git commands in your browser at try.github.io

    Initialize a new Git repository

    
    							$ mkdir myproj
    						
    
    							$ cd myproj
    						
    
    							$ git init
    						

    Initializing a repository

    init

    Checking Status

    
    							$ git status
    						

    Short Status

    
    							$ git status -s
    						

    status

    Add (stage) a file

    
    							$ git add {file}
    						
    
    							$ git add *.java
    						
    
    							$ git add *
    						

    add

    What differences exist?

    Diff of modified changes

    
    							$ git diff
    						

    Diff of staged changes

    
    							$ git diff --staged
    						

    diff

    Reset (unstage) a file

    
    							$ git reset {file-path}
    						
    
    							$ git reset *.java
    						
    
    							$ git reset *
    						

    reset

    Commit Changes

    
    							$ git commit -m '{message}'
    						

    commit

    Branching

    Create

    
    							$ git branch {branch-name}
    						

    Delete

    
    							$ git branch -d {branch-name}
    						

    Branches in a Nutshell

    branch

    Checkout

    
    							$ git checkout {branch-name}
    						

    checkout

    Merge

    
    							$ git merge {branch-name}
    						

    merge

    Resolve conflicts

    
    							$ git mergetool
    						

    mergetool

    Rebase

    Replay a changeset by rewinding to a common ancestor and reapplying each change in turn.

    This keeps history more linear and easier to read.

    
    							$ git rebase {branch-name}
    						

    Rebasing

    rebase

    What?

    Merge vs. Rebase

    Fast Forward

    
    							$ git checkout master
    						
    
    							$ git merge experiment
    						

    Tags

    Add

    
    							$ git tag -a 0.1.0 "Alpha release"
    						

    List All

    
    							$ git tag
    						

    List matching tags

    
    							$ git tag -l {search-string}
    						

    List all 1.2 tags

    
    							$ git tag -l "1.2*"
    						

    tag

    Commit Log

    
    							$ git log
    						

    Show diffs for the last n commits

    
    							$ git log -p -{n}
    						

    Show abbreviated stats

    
    							$ git log --stat
    						

    Show a graph

    
    							$ git log --graph
    						

    Viewing Commit History

    log

    Hosted solutions

    GitHub

    BitBucket

    GitLab

    VSTS

    Fork

    Your copy of a repository in at the hosting provider.

    Clone an existing repository

    
    							$ git clone {path to repo}
    						
    
    							$ git clone https://github.com/PeterEltgroth/itconf2016
    						

    Clone Existing

    clone

    Remotes

    List

    
    							$ git remote
    						

    List with URLs

    
    							$ git remote -v
    						

    Inspect

    
    							$ git remote show {optional-remote-name}
    						

    Working with remotes

    remote

    Remotes

    Add

    
    							$ git remote add {remote-name} {url}
    						

    Rename

    
    							$ git remote rename {old-name} {new-name}
    						

    Remove

    
    							$ git remote rm {remote-name}
    						

    Working with remotes

    remote

    Fetch

    
    							$ git fetch {remote-name}
    						

    fetch

    Pull

    Fetch & Merge the remote branch into the current branch

    
    							$ git pull {remote-name} {remote-branch}
    						

    pull

    Push

    Push remote branch into the current branch

    
    							$ git push {remote-name} {branch-name}
    						

    push

    Rebase Warning!

    If your fork (or any other repo) already has your C4 commit and then you rebase locally, it WILL cause problems.

    Pull Request

    A request that a change you made be pulled back into a branch on another copy of the repository.

    As a developer submitting a PR, it is generally your responsibility to catch up and resolve any merge conflicts with the branch your PR is targeting.

    Managing Pull Requests

    Continuous Integration

    Jenkins

    Registration Build

    Build Details

    Site Test

    Resources

    About Git

    Git Documentation

    Try Git @ GitHub

    Git Real @ Code School

    Git it Together on GitHub

    Created with reveal.js
    Source code located at: GITitTogether