Git 101

A Gentle Introduction to Version Control, Git & GitHub

Kosmas Pouianou, Kostas Minaidis
(Instructors at Social Hackers Academy)

Version 0.1.0 | 26/04/2018

Table of Contents

  • Version Control
  • Git
  • GitHub
  • Hands-on

Prelude

What does it mean to work
without Version Control?

Your Daily Tasks

Create Things

Save Things

Edit Things

Save the Things Again

index.html
style.css
 

								
Monday
Tuesday
Wednesday
Thursday
Friday

No VCS means:

No control over our changes. They are permanent.

We cannot revert to a previous state.

There is no descriptive history of the changes.

It is almost impossible to work collaboratively.

Version Control System (VCS)

A system that records changes to a file or set of files
over time so that you can recall specific versions later.

A system that enables collaboration:
A Team of people working on one Project, on the same files.

It allows you to:

  • • Revert selected files back to a previous state
  • • Revert the entire project back to a previous state
  • • Compare changes over time
  • • See who last modified something that might be causing a problem

Using a VCS also generally means that
if you screw things up or lose files, you can easily recover.

Version History

Monday
header: #ff69b4
								
Tuesday
footer: #185d2c
								
Wednesday
header: #457aa5, footer: #457aa5
								
Thursday
header: #a57d45
								
Friday
header: #457aa5, footer: #ad2222
								
index.html
style.css
 

								

Your Daily Tasks

Create Things

Save Things

Edit Things

Save the Things Again

Your Daily Tasks

Create Things

Save Things

Edit Things

Save the Things Again

^

VCS comes into play at this stage.

Version Control Systems keep track of every file change,
and create a Version History (Database)
from these file changes (Versions).

Version Control Systems allow the user to store
a short descriptive message along with every single change.
A VCS can tell us who did what and when:
"On April 23 the user Kostas removed lines 30-36 from the file style.css"

What is Git?

Git is a widely used and very popular VCS.

It is a tool that we install on our computers and tracks
file changes and keeps a history of them (Commits)

It allows multiple users to work
on a Project at the same time.

No Waiting: Continue working while other people
are working on the same Project at the same time.

It supports a powerful feature called: Feature Branches.

Git is a Distributed VCS.
The Database of changes (Version History) is stored
on a central Server and shared among all users.

The Distributed nature of Git enables us to keep track of
each user's changes and contributions over time.

A Real Life Example of a Git Workflow in Production

How does Git work?

Step 1

In order for Git to start tracking our Project's files
we first have to initialize our Project's folder

Go to your Project Directory:
> cd myProject

Initialize with Git:
> git init

Git has just created a .git folder inside your Project's folder.
All tracking data and information will be stored inside this folder.

That's it! Git can now start tracking all changes.

The Three Stages of Git

Working Directory
Untracked Files

Staging Area
Tracked Files

Git Repository
Commited Files
(Version History)

-- git add -->
-- git commit -->
Files in a repository go through three stages
before being under version control with git:

Working Directory

Staging Area

Git Repository

Untracked Files: Files exist but they are not part of Git's version control.

Tracked Files: Files have been added to Git's version control using the git add command but changes have not been commited (stored) yet.

Commited Files: Changes have been commited using the git commit command and are now stored in your Git Repository (Database of changes)


The git status command is used to understand
what stage the files in a repository are at.

GitHub

Master (Local Repo) --> Origin (Remote Repo)

Local / Remote Repo Synchronization

Enough Theory: Let's Practice!

Prerequisites:

1) Install Git* and test that everything is working by running:
git --version
Download for Windows
Download for Linux
Download for Mac

2) Create a GitHub Account

*Windows: Check Git Bash

3) Configure Git

git config --global user.name "Joe"

git config --global user.email "your@email.com"

Git Hands-On

What we'll do...

[ Demo Session ]

Let's Try Git

Click Here.

Commit(s): Git's way of saving (changes) into its History of Changes Database.

Repository (Repo) / Project: All Changes are tracked here

Staging (Area): Control what gets Commited.

Working Directory: Where our Project lives

References and Sources:

• Atlassian Git Tutorial: What is Version Control
• Working With Git
Learn Git in 30 Minutes
• The three stages of Git
• Git Tutorial for Beginners: 4 Git Concepts and Architecture
• Mary Rose Cook: Git from the inside out
• GitHowTo: A guided tour through the fundamentals of Git.
• A Visual Git Reference
• Learn Git Branching
• A Grip On Git: A Simple, Visual Git Tutorial

That's all Folks!