GIT & github


Why should I use version control?

Why should I use version control?

Have you ever:

  • Made a change to code, realized it was a mistake and wanted to revert back?
  • Lost code or had a backup that was too old?
  • Had to maintain multiple versions of a product?
  • Wanted to see the difference between two (or more) versions of your code?
  • Wanted to prove that a particular change broke or fixed a piece of code?

Why should I use version control?

Have you ever:

  • Wanted to review the history of some code?
  • Wanted to submit a change to someone else's code?
  • Wanted to share your code, or let other people work on your code?
  • Wanted to see how much work is being done, and where, when and by whom?
  • Wanted to experiment with a new feature without interfering with working code?

Why git?

  • Speed
  • Simple design
  • Strong support for non-linear development (thousands of parallel branches)
  • Fully distributed
  • Able to handle large projects like the Linux kernel efficiently (speed and data size)

why github?

A social network for programmers :)

history of git

Git basics

Snapshots, Not Differences

git basics

Nearly Every Operation Is Local

You have the entire history of the project right there on your local disk

Git Has Integrity

Everything in Git is check-summed 

Git Generally Only Adds Data

it is very difficult to lose data

git basics

The Three States

Getting Started

config git

git config {key} {value}

git config --list

Getting Started


git help <verb>

git help config

source ~/.git-completion.bash

Setting Up a Git Repository

$ git init
$ git init --bare <directory>

$ git clone git://

Setting Up a Git Repository

svn vs git

Setting Up a Git Repository

$ git add *.py
$ git add README

$ git commit -m 'initial project version'

Setting Up a Git Repository

Setting Up a Git Repository

inspecting a git repository

$ git status 

Git Tutorial: git status

$ git log 

inspecting a Git Repository

inspecting a Git Repository

$ git blame <file>

other useful commands

$ cat .gitignore
$ git diff
$ git diff --staged
$ git rm <file>
$ git rm --cached <file>
$ git mv <file_from> <file_to>

Undoing Things

$ git commit --amend

$ git reset 

$ git checkout <commit> <file>
$ git checkout <branch>

git revert <commit>

git clean 

undoing things

reset vs revert

Git Tutorial: Revert vs Reset

Don’t Reset Public History

Git Branches

Git Tutorial: Branching and Merging

git branches

$ git branch <branch>
Git Tutorial: Create new branch     Git Tutorial: git branch

git branches

$ git checkout <branch>

Git Tutorial: Switch between multiple features in a single repo with git checkout.      Git Tutorial: Attached vs Detached Head

git branches

$ git merge 
$ git merge --no-ff 

fast-forward 3-way merge

Git Tutorial: Fast-forward merge       Git Tutorial: Three way merge

Resolving Conflicts
$ git merge some_branch
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

Working with Remotes

$ git remote
$ git remote add test 

$ git fetch <remote> <branch>
$ git branch -r
$ git merge origin/master

 git pull <remote> <branch>

git push <remote> <branch>

Git Work-flows

getting stated with github

useful links and references



git & github

By Rafael Laverde

git & github

  • 2,137