Version control with
Git and GitHub

Szymon Grabia

Version Control System

System that records changes to a set of files over time

  • restoration of files back to a previous state
  • comparison of changes over time
  • transparent cooperation

What is Git?

Distributed Version Control System

Main features:

  • branching system for non-linear development
  • primarily local repositories
  • preservation and integrity of change history
  • 3 stages of files

Centralized VCS

shared

repository

developer

developer

developer

Distributed VCS

shared

repository

developer

developer

developer

The Three Stages

Working

directory

Staging area

Repository

Local

Remote

Repository

git add

git commit

git push

git pull

git checkout

Git commits

Git identity

git config --global user.name "John Doe"
git config --global user.email "johndoe@example.com"

Initialize git repository

git init

Show the working tree status

git status

Add files to staging area

git add FILE

Commit files

git commit -m "MESSAGE"

Commit messages

The seven rules of a great Git commit message

  1. Separate subject from body with a blank line
  2. Limit the subject line to 50 characters
  3. Capitalize the subject line
  4. Do not end the subject line with a period
  5. Use the imperative mood in the subject line
  6. Wrap the body at 72 characters
  7. Use the body to explain what and why vs. how

Show changes in tracked files

git diff

Exit with "q"

Git Branching

Branching

C1

C2

master

Branching

C1

C2

master

test

git branch test

Branching

C1

test

C2

master

git checkout test

Branching

C1

test

C2

C3

master

Branching

C1

test

C2

C3

C4

master

Branching

C1

test

C2

C3

C4

C5

master

Branching

C1

test

C2

C3

C4

C5

C6

master

Branching

C1

master

test

C2

C3

C4

C5

C7

C6

git checkout master
git merge test

Show commit history

git log [--graph]

Exit with "q"

Branching

GitFlow

Merge conflicts

Merge conflicts

git merge test

Ignore files

# .gitignore

# ignore all files ending with ".log"
*.log

# BUT don't ignore "important.log"
!important.log

# ignore all directories named "data"
data/

# ignore directories named "data" in the project root
/data/

A collection of useful .gitignore templates:

https://www.gitignore.io/

Don't store data in repositories!

Git stash

git stash
git stash apply
OR
git stash pop
git stash list
git stash show -a

Much more...

git tag

git rebase

git rm

git reset

git blame

The Three Stages

Working

directory

Staging area

Repository

Local

Remote

Repository

git add

git commit

git push

git pull

git checkout

Repository hosting

GitHub flow

SSH keys

ssh-keygen -t rsa -b 4096 -C "szymon.grabia@gmail.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub

Clone remote repository

git clone https://github.com/LaVestima/ngseminar-git-github.git

Clone remote repository

git remote -v

Push changes to remote

git push [<repository> [<refspec>...]]
git push origin master

Pull changes from remote

git pull [<repository> [<refspec>...]]
git pull origin master

Awesome lists about all kinds of interesting topics

NGSeminar: Version control with git and github

By Szymon Grabia