2016-11-16

What is version control?

  • A system that keeps records of your changes
  • Allows for collaborative development
  • Allows you to know who made what changes and when
  • Allows you to revert any changes and go back to a previous state

What is version control?

  • Distributed version control
  • Users keep entire code and history on their location machines
    • Users can make any changes without internet access
    • (Except pushing and pulling changes from a remote server)

What is git?

  • Started in 2005
  • Created by Linus Torvald to aid in Linux kernel development

Other version control systems

  • RCS
  • Concurrent Versions System (CVS)
  • Subversion (SVN)
  • Perforce
  • Mercurial
  • Bazaar
  • etc…

How does git work?

  • Can be complicated at first, but there are a few key concepts
  • Important git terminology in following slides are blue

The Git Workflow

The simplest use of git:

  • Modify file in your working directory
  • Stage the files, adding snapshots of them to your staging area
  • Commit, takes files in the staging area and stores that snapshot permanently to your git directory (.git)
  my_working_dir/ <== the working directory
  |-.git/         <== the local repository
  |  |- ...files  <== files/folder git uses to capture the current
  |                   and previous states of the working directory
  |- file1     \
  |- dir1/      | <== files/folders in the working directory
  |  |- file2  /

Key Concepts: Snapshots

  • The way git keeps track of your code history
  • Essentially records what all your files look like at a given point in time
  • You decide when to take a snapshot, and of what files
  • Have the ability to go back to visit any snapshot
    • Your snapshots from later on will stay around, too

Key Concepts: Commit

  • The act of creating a snapshot
  • Can be a noun or verb
    • “I commited code”
    • “I just made a new commit”
  • Essentially, a project is made up of a bunch of commits

Key Concepts: Commit

  • Commits contain three pieces of information:
  1. Information about how the files changed from previously
  2. A reference to the commit that came before it
    • Called the “ parent commit
  3. A hash code name
    • Will look something like: f2d2ec5069fc6776c80b3ad6b7cbde3cade4e

Key Concepts: Repositories

  • Often shortened to ‘ repo
  • A collection of all the files and the history of those files
    • Consists of all your commits
    • Place where all your hard work is stored

Key Concepts: Repositories

  • Can live on a local machine or on a remote server (e.g. GitHub)
  • The act of copying a repository from a remote server is called cloning
  • Cloning from a remote server allows teams to work together

Key Concepts: Repositories

  • The process of downloading commits that don’t exist on your machine from a remote repository is called pulling changes
  • The process of adding your local changes to the remote repository is called pushing changes

Key Concepts: Branches

  • All commits in git live on some branch
  • But there can be many, many branches
  • The main branch in a project is called the master branch

So, what does a typical project look like?

  • A bunch of commits linked together that live on some branch, contained in a repository

So, what is HEAD?

  • A reference to the most recent commit
    • (in most cases – not always true!)

So, what is MASTER?

  • The main branch in your project
    • Doesn’t have to be called master, but almost always is

Branching and Merging

  • Create a new branch when making a change while not wanting to break things on the master branch
    • The start of a branch points to a specific commit.
    • Can be called anything
  • Once you’re done with your change, you merge it back into master

Key Concepts: How do you make a commit anyway?

  • There are a lot of ‘states’ and ‘places’ a file can be
  • Local on your computer: the ‘ working directory’ or on another computer/server: the ' remote'
  • When a file is ready to be put in a commit you put it in the ‘ staging area’ (' stage the file')

File states

Files in your working directory can be in four different states in relation to the current commit

Ok, but how do you actually do it?

You learn linux and do it on the command line:

$ mkdir my_project
$ cd my_project
$ git init
$ echo "# README" > README.md
$ git add README.md
$ git commit -m 'Added README.md file'
$ echo "This is my fabulous project" >> README.md
$ git add README.md
$ git commit -m 'Updated README.md' README.md

or using a…

Graphical user interface

  • SourceTree (or some other…)

What is GitHub?

  • www.github.com
  • Largest web-based git repository hosting service
    • Hosts ‘remote repositories’
  • Allows for code collaboration and sharing with anyone online
  • Adds extra functionality on top of git
    • UI, documentation, bug tracking, feature requests, pull requests, and more!

Useful git resources (mainly command line)

Slide source acknowledgements

Hands-on session