git is simpler than you think

89
Git Is Simpler Than You Think

Upload: ricardoerikson

Post on 30-Sep-2015

23 views

Category:

Documents


0 download

DESCRIPTION

Introduction to Git with distributed version control system. This document presents workflows, and the main concepts and commands used in Git.

TRANSCRIPT

  • Git Is Simpler Than You Think

  • $git me.name Ricardo Erikson$git me.email [email protected]

  • Scott Chacon (github co-founder)

    If you are comfortable with version control and its a version control that is not git, you are going to hate git when

    you start using it.

  • git is an open source, distributed version control

    system designed for speed and efficiency.

  • References

    http://gitref.org

    http://try.github.io

    http://git-scm.com/doc

    http://stackoverflow.com

  • distributed git

  • every developer is potentially both a node or a hub

  • remote repository

  • remote repository

    local repository

  • remote repository

    local repository

    git clone git pull

    git remote

  • remote repository

    local repository

    git clone git pull

    git remotegit push

  • you do a clone of the entire repository

  • which means

  • which means

    everything is fast

    every clone is a backup

    work offline

  • no network needed

    performing a diff

    viewing file history

    committing changes

  • no network needed

    merging branches

    obtaining other revisions of a file

    switching branches

  • subversion-style workflow

  • subversion-style workflow

    shared repository public

  • subversion-style workflow

    shared repository

    developer developer developer

    public

    private

  • subversion-style workflow

    shared repository

    developer developer developer

    public

    private

  • integration manager workflow

  • integration manager workflow

    publicprivate

  • integration manager workflow

    blessed repository

    publicprivate

  • integration manager workflow

    blessed repository

    developer public

    developer public

    publicprivate

  • integration manager workflow

    blessed repository

    developer public

    developer public

    integration manager

    publicprivate

  • integration manager workflow

    blessed repository

    developer public

    developer public

    developer private

    developer private

    integration manager

    publicprivate

  • integration manager workflow

    blessed repository

    developer public

    developer public

    developer private

    developer private

    integration manager

    publicprivate

    git push to publish the changes (commits) to the remote repository

  • integration manager workflow

    blessed repository

    developer public

    developer public

    developer private

    developer private

    integration manager

    publicprivate

    merge request

  • integration manager workflow

    blessed repository

    developer public

    developer public

    developer private

    developer private

    integration manager

    publicprivate

    git push to publish the local changes to the blessed repository

  • integration manager workflow

    blessed repository

    developer public

    developer public

    developer private

    developer private

    integration manager

    publicprivate

    git pull to update the local repository

  • branching and merging

  • (git allows and encourages) multiple local branches

    !

    fast creation, merging and deletion !

    branching is cheap

  • you can do things like

    frictionless context switching

    role-based codelines & feature based workflow

    disposable experimentation

  • frictionless context switching

    master

    develop

  • frictionless context switching

    master

    develop

    topic branches

  • frictionless context switching

    master

    develop

    topic branches

  • frictionless context switching

    master

    develop

    topic branches

  • role-based codelines & feature based workflow

    master

    develop

  • role-based codelines & feature based workflow

    master

    develop

    production code

  • role-based codelines & feature based workflow

    master

    develop

    production code

    merge

  • role-based codelines & feature based workflow

    master

    develop

    production code

    merge

    feature/x

    feature/y

    bugfix/z

  • disposable experimentation

    master

    develop

    topic branches

  • disposable experimentation

    master

    develop

    topic branches

  • disposable experimentation

    master

    develop

    topic branches

  • disposable experimentation

    master

    develop

    topic branches

  • staging area

  • staging area

    Intermediate area where commits can be formatted and reviewed before

    completing the commit

  • Automatically stage files that have been modified

    and deleted

    New files are not affected!

    $ git commit -a

  • Automatically stage files that have been modified

    and deleted

    New files are not affected!

    working directory

    staging area

    repository

    $ git commit -a

  • Getting and Creating Projects

  • getting a git repository

  • getting a git repository

    initialize a new one from an existing directory

  • getting a git repository

    initialize a new one from an existing directory

    clone one from a public Git repository

  • git init

  • git init$ mkdir mygitproject

  • git init$ mkdir mygitproject$ cd mygitproject

  • git init$ mkdir mygitproject$ cd mygitproject$ echo README >> README

  • git init$ mkdir mygitproject$ cd mygitproject$ echo README >> README$ ls -a. .. README

  • git init$ mkdir mygitproject$ cd mygitproject$ echo README >> README$ ls -a. .. README

    $ git initInitialized empty Git repository in /tmp/mygitproject/.git/

  • git init$ mkdir mygitproject$ cd mygitproject$ echo README >> README$ ls -a. .. README

    $ git initInitialized empty Git repository in /tmp/mygitproject/.git/

    $ ls -a. .. .git README

  • git init$ mkdir mygitproject$ cd mygitproject$ echo README >> README$ ls -a. .. README

    $ git initInitialized empty Git repository in /tmp/mygitproject/.git/

    $ ls -a. .. .git README

  • git init

  • git init$ cat .git/config[core]

    repositoryformatversion = 0filemode = truebare = falselogallrefupdates = trueignorecase = trueprecomposeunicode = false

  • git clone

  • git clone$ git clone git://github.com/schacon/simplegit.git

    Cloning into 'simplegit'...remote: Reusing existing pack: 13, done.remote: Total 13 (delta 0), reused 0 (delta 0)Receiving objects: 100% (13/13), done.Resolving deltas: 100% (2/2), done.

  • git clone$ git clone git://github.com/schacon/simplegit.git

    $ cd simplegit

    Cloning into 'simplegit'...remote: Reusing existing pack: 13, done.remote: Total 13 (delta 0), reused 0 (delta 0)Receiving objects: 100% (13/13), done.Resolving deltas: 100% (2/2), done.

  • git clone$ git clone git://github.com/schacon/simplegit.git

    $ cd simplegit$ ls -a

    Cloning into 'simplegit'...remote: Reusing existing pack: 13, done.remote: Total 13 (delta 0), reused 0 (delta 0)Receiving objects: 100% (13/13), done.Resolving deltas: 100% (2/2), done.

    . .. .git README Rakefile lib

  • git clone

  • git clone$ cat .git/config[core]

    repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = false

    [remote "origin"]url = git://github.com/schacon/simplegit.git fetch = +refs/heads/*:refs/remotes/origin/*

    [branch "master"]remote = origin merge = refs/heads/master

  • Basic Snapshotting

  • git add adds file contents to the staging areagit status view the status of your file in the working directory and stage area

  • git add adds file contents to the staging area

    $ git status -s?? README?? hello.rb

    git status view the status of your file in the working directory and stage area

  • git add adds file contents to the staging area

    $ git status -s?? README?? hello.rb

    $ git add README hello.rbA READMEA hello.rb

    git status view the status of your file in the working directory and stage area

  • git add adds file contents to the staging area

    $ git status -s?? README?? hello.rb

    $ git add README hello.rbA READMEA hello.rb

    $ vim README$ git status -sAM READMEA hello.rb

    git status view the status of your file in the working directory and stage area

  • git diff shows diff of what is staged and what is modified but unstaged

  • git diff shows diff of what is staged and what is modified but unstaged

    $ vim hello.rb$ git status -s M hello.rb$ git diffdiff --git a/hello.rb b/hello.rbindex d62ac43..8d15d50 100644--- a/hello.rb+++ b/hello.rb@@ -1,7 +1,7 @@ class HelloWorld! def self.hello- puts "hello world"+ puts "hola mundo" end! end

  • other diff commands

    git diff --cached shows diff of staged changes

    git diff HEAD shows diff of all staged or unstaged changes

    git diff --stat shows summary of changes instead of a full diff

  • git commit records a snapshot of the staging area

  • git commit records a snapshot of the staging area

    $ git config --global user.name 'Your Name'$ git config --global user.email [email protected]

  • git commit records a snapshot of the staging area

    $ git config --global user.name 'Your Name'$ git config --global user.email [email protected]

    $ git add hello.rb $ git status -sM hello.rb$ git commit -m 'my hola mundo changes'[master 68aa034] my hola mundo changes 1 files changed, 2 insertions(+), 1 deletions(-)

  • git commit records a snapshot of the staging area

    $ git config --global user.name 'Your Name'$ git config --global user.email [email protected]

    $ git add hello.rb $ git status -sM hello.rb$ git commit -m 'my hola mundo changes'[master 68aa034] my hola mundo changes 1 files changed, 2 insertions(+), 1 deletions(-)

    $ git status# On branch masternothing to commit (working directory clean)

  • basic git workflow

    1 Edit filesEclipse/Sublime/vim/emacs/etc

  • basic git workflow

    1 Edit filesEclipse/Sublime/vim/emacs/etc

    2 Stage the changes$git add (file)

  • basic git workflow

    1 Edit filesEclipse/Sublime/vim/emacs/etc

    2 Stage the changes$git add (file)

    3 Review the changes$git diff / $git status

  • basic git workflow

    1 Edit filesEclipse/Sublime/vim/emacs/etc

    2 Stage the changes$git add (file)

    3 Review the changes$git diff / $git status

    4 Commit the changes$git commit

  • or

    1 Edit filesEclipse/Sublime/vim/emacs/etc

  • or

    1 Edit filesEclipse/Sublime/vim/emacs/etc

    2 Stage and commit$git commit -a