Keep GIT Simple

... journey through space-time

by Santiago Rojo

Agenda

  • About VCS
  • About Git
  • Anatomy of the repository
  • Anatomy of a commit
  • Anatomy of a branch
  • Git commands
    • merge vs. rebase
  • Remotes
  • Branching model (Git vs. SVN)
    • Recommended Git flow
  • Use case: LXF

What is a VCS?

... anyone will tell:

“Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.”

But, only a few know the truth...

What kind of VCS exists?

Centralized vs. Decentralized vs. Distributed

Network diagrams

VCS tools

Centralized Distributed
  • CVS
  • SVN
  • Mercurial
  • Bazaar
  • Git
Git logo

Why Git?

Git off-line

  • Faster
  • Diff between everything
  • See the full log
  • Commit changes
  • Merge/Rebase branches
  • Get a previous version of a file
  • Switch branches
  • and more

How Git works?

  • Snapshots, not Differences
  • Integrity (sha1)
  • Only adds data

What's inside?

Anatomy of the repository

Anatomy of a commit

Branches

... are just pointers

Git commands

Wait! What about head?

Ok, danke!

Git commands

152 commands

111 "plumbing" commands

152 commands

41 "porcelain" commands

21 "essentials" commands

Configurations


$ git config --global user.name "Santiago Rojo"

$ git config --global user.email santiago.rojo@graion.com

$ git config --global color.ui true

$ git config --global merge.tool meld

Initialize a repository


$ git init
Initialized empty Git repository in /home/tiagox/KeepGITSimple/.git/

Using an existing repository


$ git clone http://dev.graion.com/git/keepgitsimple
Cloning into 'keepgitsimple'...
remote: Counting objects: 4665, done.
remote: Compressing objects: 100% (2281/2281), done.
remote: Total 4665 (delta 2715), reused 4136 (delta 2247)
Receiving objects: 100% (4665/4665), 16.39 MiB | 227.00 KiB/s, done.
Resolving deltas: 100% (2715/2715), done.
Checking connectivity... done

Protocols

  • ssh://
  • http[s]://
  • git://

Adding files and changes

all


$ git add .

files


$ git add README.md

patterns


$ git add src/*.java

interactive


$ git add -p

Commiting changes


$ git commit

$ git commit -m "Commit message."

add + commit


$ git commit -am "Commit message."

Cherry picking


$ git cherry-pick 5123dad9ce82d6a91b2d027015bfe9d907dcda7b

Ignoring things

  • .gitignore
  • .git/info/exclude

.netbeans
.DS_Store
*.o
*.dll
*.class

Status


$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   index.html
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   index.html
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       README.md

Log


$ git log
commit 1be40da451afae95451b47bc0d81309f31a65e5b
Author: Santiago Rojo <santiago.rojo@graion.com>
Date:   Thu Sep 5 16:49:04 2013 -0300

    Add HTML structure to index.html.

commit 5123dad9ce82d6a91b2d027015bfe9d907dcda7b
Author: Santiago Rojo <santiago.rojo@graion.com>
Date:   Thu Sep 5 11:00:53 2013 -0300

    Add index file.

what's in master but not in development


$ git log development..master

commit 1be40da451afae95451b47bc0d81309f31a65e5b
Author: Santiago Rojo <santiago.rojo@graion.com>
Date:   Thu Sep 5 16:49:04 2013 -0300

    Add HTML structure to index.html.

Alias


$ git config --global alias.gol "log --graph --pretty=format:'%Cred%h%Creset - %C(blue)%an%Creset
%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"

$ git gol

Create branches


$ git branch playground

create + switch


$ git checkout -b development
Switched to a new branch 'development'

List branches


$ git branch
* development
  master
  playground

Switch branches

to another branch


$ git checkout playground
Switched to branch 'playground'

... or go anywhere


$ git checkout 5123dad9ce82d6a91b2d027015bfe9d907dcda7b
Note: checking out '5123dad9ce82d6a91b2d027015bfe9d907dcda7b'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 5123dad... Add index file.

Delete branches


$ git branch -d playground

$ git branch -D playground

Stashing


$ git stash

$ git stash save "Comments"

$ git stash list

$ git stash apply

$ git stash drop

apply + drop


$ git stash pop

Tags

create


$ git tag -a R01 -m "First release"

list


$ git tag
R01

Merge


$ git checkout master
Switched to a new branch 'master'
$ git merge feature

$ git merge feature
Updating 306eb60..56a2247
Fast-forward
 index.html | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

$ git checkout master
Switched to a new branch 'master'
$ git merge feature

$ git merge feature
Auto-merging index.html
Merge made by the 'recursive' strategy.
 index.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Solving conflicts


$ git mergetool

$ git commit

Fast-forward

Recursive strategy

Rebase


$ git checkout master
Switched to a new branch 'master'
$ git rebase feature

$ git rebase feature
First, rewinding head to replay your work on top of it...
Fast-forwarded master to feature.

$ git checkout master
Switched to branch 'master'
$ git rebase feature

$ git rebase feature
First, rewinding head to replay your work on top of it...
Applying: c3

DON'T

let's try again


$ git checkout feature
Switched to branch 'feature'
$ git rebase master

$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: c4
Applying: c5
Applying: c6

$ git checkout master
Switched to branch 'master'
$ git merge feature
Updating 306eb60..56a2247
Fast-forward
 index.html | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Solving conflicts


$ git mergetool

$ git rebase --continue

Wrong rebase

Rebase-Merge

Remotes

Add remotes


$ git remote add graion http://dev.graion.com/git/keepgitsimple

List remotes


$ git remote
origin
graion

show details


$ git remote graion
git remote show origin
* remote graion
  Fetch URL: http://dev.graion.com/git/keepgitsimple
  Push  URL: http://dev.graion.com/git/keepgitsimple
  HEAD branch: master
  Remote branches:
    development   tracked
    master        tracked
  Local branches configured for 'git pull':
    development   rebases onto remote development
    master        merges with remote master
  Local refs configured for 'git push':
    development   pushes to development (up to date)
    master        pushes to master      (up to date)

Fetching data


$ git fetch origin

fetch + merge :S


$ git pull origin

fetch + rebase :)


$ git pull origin --rebase

Publishing changes

only the first time


$ git push origin local_branch:remote_branch --set-upstream

then just use


$ git push

don't be proud of use


$ git push origin local_branch:remote_branch --force

Branching model

Use case


Applications and tools

Linux


$ sudo apt-add-repository ppa:pdoes/ppa
$ sudo apt-get update
$ sudo apt-get install git gitk

Windows

  1. http://git-scm.com/download/win
  2. Next, next, next...

gitk

SmartGit

Links





Questions?





Are you sure?





Thank you