@LorenzoBaracchi
A System that records changes to files over time,
so that you can recall specific versions later.
Version Control System
Alice
Version Control System
Local Centralized Distributed
vers.3
vers.2
vers.1
File
vers.3
vers.2
vers.1
File File
Alice Bob
File
v.3
v.2
v.1
Bob
File
v.3
v.2
v.1
vers.3
vers.2
vers.1
Git Basic
Working
Directory
Staging
Area
Repository
Git Basic
Working
Directory
Staging
Area
Repository
My File
Git Basic
Working
Directory
Staging
Area
Repository
My File
git add
changes 

to My File
Git Basic
Working
Directory
Staging
Area
Repository
My File
git add git commit
changes 

to My File
Local
Git Basic
Working
Directory
Staging
Area
Repository
My File
git add git commit
changes 

to My File
Git Basic
Local
Working
Directory
Staging
Area
Repository
My File
git add git commit
changes 

to My File
Git Basic
Local
Working
Directory
Staging
Area
Repository
My File
git add git commit
changes 

to My File
Remote
Git Basic
Local
Working
Directory
Staging
Area
Repository
My File
git add git commit
changes 

to My File
Remote
git push
3 States
Working
Directory
Staging
Area
Repository
Modified Staged Committed
git
101
Recording Changes
History of Changes
Undo
Going Remote
git status
Recording Changes
show in which state a file is:
modified, staged, committed
Working
Directory
Staging
Area
Repository
git status
Recording Changes
show in which state a file is:
modified, staged, committed
Working
Directory
Staging
Area
Repository
≠ ≠
git diff
Recording Changes
shows changed made but not yet staged
--staged shows changes staged but not yet committed
Working
Directory
Staging
Area
Repository
git diff
Recording Changes
shows changed made but not yet staged
--staged shows changes staged but not yet committed
Working
Directory
Staging
Area
Repository
diff diff --staged
git add <file, dir>
Recording Changes
“prepare this content for the next commit”
saves only current modifications, not futures modifications
Working
Directory
Staging
Area
Repository
git add <file, dir>
Recording Changes
“prepare this content for the next commit”
saves only current modifications, not futures modifications
Working
Directory
Staging
Area
Repository
puts “Hello
World
Everybody”
git add <file, dir>
Recording Changes
“prepare this content for the next commit”
saves only current modifications, not futures modifications
Working
Directory
Staging
Area
Repository
puts “Hello
World
Everybody”
- Words
+ Everybody
git add <file, dir>
Recording Changes
“prepare this content for the next commit”
saves only current modifications, not futures modifications
Working
Directory
Staging
Area
Repository
puts “Hello
World
Everybody”
- Words
+ Everybody
git rm <file, dir>
Recording Changes
Removes the specified file(s) from staging area and current
--cached do not remove the file from the working directory
Working
Directory
Staging
Area
Repository
foo.rb
bar.rb
foobar.rb
foo.rb
bar.rb
foobar.rb
git rm <file, dir>
Recording Changes
Removes the specified file(s) from staging area and current
--cached do not remove the file from the working directory
Working
Directory
Staging
Area
Repository
foo.rb
bar.rb
foobar.rb
foo.rb
bar.rb
foobar.rb
git commit
Recording Changes
Saves the changes made in the staging area to the repository
Working
Directory
Staging
Area
Repository
puts “Hello
World
Everybody”
- Words
+ Everybody
git commit
Recording Changes
Saves the changes made in the staging area to the repository
Working
Directory
Staging
Area
Repository
puts “Hello
World
Everybody”
- Words
+ Everybody
git log
History of Changes
Lists informations about commits in reverse chronological order
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date: Mon Mar 17 21:52:11 2008 -0700
changed the version number
commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 16:40:33 2008 -0700
removed unnecessary test
commit a11bef06a3f659402fe7563abf99ad00de2209e6
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 10:31:28 2008 -0700
first commit
git log
History of Changes
Lists informations about commits in reverse chronological order
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date: Mon Mar 17 21:52:11 2008 -0700
changed the version number
commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 16:40:33 2008 -0700
removed unnecessary test
commit a11bef06a3f659402fe7563abf99ad00de2209e6
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 10:31:28 2008 -0700
first commit
git log -p
History of Changes
Shows differences introduced by every commit
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date: Mon Mar 17 21:52:11 2008 -0700
changed the version number
diff --git a/Rakefile b/Rakefile
index a874b73..8f94139 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = "simplegit"
- s.version = "0.1.0"
+ s.version = "0.1.1"
s.author = "Scott Chacon"
s.email = "schacon@gee-mail.com"
s.summary = "A simple gem for using Git in Ruby code."
git log -p
History of Changes
Shows differences introduced by every commit
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date: Mon Mar 17 21:52:11 2008 -0700
changed the version number
diff --git a/Rakefile b/Rakefile
index a874b73..8f94139 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = "simplegit"
- s.version = "0.1.0"
+ s.version = "0.1.1"
s.author = "Scott Chacon"
s.email = "schacon@gee-mail.com"
s.summary = "A simple gem for using Git in Ruby code."
Where
What
git log OPTIONS
History of Changes
--stat shows list of modified files
-1
-2
-n
shows last commit
shows last 2 commits
shows last n commits
-S<string>
only shows commits
adding/removing <string>
git commit --amend
Undo
takes changes in staging area and adds them to the previous commit
Working
Directory
Staging
Area
Repository
list of
changes
git commit --amend
Undo
takes changes in staging area and adds them to the previous commit
Working
Directory
Staging
Area
Repository
list of
changes
git reset HEAD <file>
Undo
Removes the selected file from the staging area
Working
Directory
Staging
Area
Repository
puts “Hello
World
Everybody”
- Words
+ Everybody
git reset HEAD <file>
Undo
Removes the selected file from the staging area
Working
Directory
Staging
Area
Repository
puts “Hello
World
Everybody”
git checkout -- <file>
Undo
Discards changes of the file in the working directory
Working
Directory
Staging
Area
Repository
puts “Hello
World
Everybody”
git checkout -- <file>
Undo
Discards changes of the file in the working directory
Working
Directory
Staging
Area
Repository
puts “Hello
World
Everybody”
puts “Hello
World”
git push <remote_name> <branch_name>
Going Remote
Shares the modifications with the remote repository
Local
Working
Directory
Staging
Area
Repository
My File
changes 

to My File
Remote
master
branch
git push <remote_name> <branch_name>
Going Remote
Shares the modifications with the remote repository
Local
Working
Directory
Staging
Area
Repository
My File
changes 

to My File
Remote
git push
master
branch
git fetch <remote_name>
Going Remote
Retrieves data from the remote repository (do not merge)
Local
Working
Directory
Staging
Area
Repository
My File changes 

to My File
Remote
1
master
2
3
5
4
1
2
3
3
git fetch <remote_name>
Going Remote
Retrieves data from the remote repository (do not merge)
Local
Working
Directory
Staging
Area
Repository
My File changes 

to My File
Remote
1
master
2
3
5
4
1
2
3
3
5
4
git pull
Going Remote
Retrieves data from the remote repository (and merge)
Local
Working
Directory
Staging
Area
Repository
My File changes 

to My File
Remote
1
master
2
3
5
4
1
2
3
3
git pull
Going Remote
Retrieves data from the remote repository (and merge)
Local
Working
Directory
Staging
Area
Repository
My File changes 

to My File
Remote
1
master
2
3
5
4
1
2
3
4
5
3
Branching
branch: you diverge from the main line of development
and continue to do work without messing with that main line
master
master
mybranch
$ git branch mybranch
master
mybranch
$ git branch mybranch
$ git checkout mybranch
master
mybranch
$ git branch mybranch
$ git checkout mybranch
$ git commit
master
mybranch
$ git branch mybranch
$ git checkout mybranch
$ git commit
$ git commit
master
mybranch
$ git branch mybranch
$ git checkout mybranch
$ git commit
$ git commit
$ git checkout master
Merging
master
mybranch
master
mybranch
$ git checkout master
mybranch
master
$ git checkout master
$ git merge mybranch
master
mybranch
mybranch
master
$ git commit
mybranch
$ git commit
master
$ git merge mybranch
wants you to branch&merge

Git presentation

  • 1.
  • 2.
    A System thatrecords changes to files over time, so that you can recall specific versions later. Version Control System
  • 3.
    Alice Version Control System LocalCentralized Distributed vers.3 vers.2 vers.1 File vers.3 vers.2 vers.1 File File Alice Bob File v.3 v.2 v.1 Bob File v.3 v.2 v.1 vers.3 vers.2 vers.1
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
    Git Basic Local Working Directory Staging Area Repository My File gitadd git commit changes to My File Remote git push
  • 12.
  • 13.
  • 14.
    Recording Changes History ofChanges Undo Going Remote
  • 15.
    git status Recording Changes showin which state a file is: modified, staged, committed Working Directory Staging Area Repository
  • 16.
    git status Recording Changes showin which state a file is: modified, staged, committed Working Directory Staging Area Repository ≠ ≠
  • 17.
    git diff Recording Changes showschanged made but not yet staged --staged shows changes staged but not yet committed Working Directory Staging Area Repository
  • 18.
    git diff Recording Changes showschanged made but not yet staged --staged shows changes staged but not yet committed Working Directory Staging Area Repository diff diff --staged
  • 19.
    git add <file,dir> Recording Changes “prepare this content for the next commit” saves only current modifications, not futures modifications Working Directory Staging Area Repository
  • 20.
    git add <file,dir> Recording Changes “prepare this content for the next commit” saves only current modifications, not futures modifications Working Directory Staging Area Repository puts “Hello World Everybody”
  • 21.
    git add <file,dir> Recording Changes “prepare this content for the next commit” saves only current modifications, not futures modifications Working Directory Staging Area Repository puts “Hello World Everybody” - Words + Everybody
  • 22.
    git add <file,dir> Recording Changes “prepare this content for the next commit” saves only current modifications, not futures modifications Working Directory Staging Area Repository puts “Hello World Everybody” - Words + Everybody
  • 23.
    git rm <file,dir> Recording Changes Removes the specified file(s) from staging area and current --cached do not remove the file from the working directory Working Directory Staging Area Repository foo.rb bar.rb foobar.rb foo.rb bar.rb foobar.rb
  • 24.
    git rm <file,dir> Recording Changes Removes the specified file(s) from staging area and current --cached do not remove the file from the working directory Working Directory Staging Area Repository foo.rb bar.rb foobar.rb foo.rb bar.rb foobar.rb
  • 25.
    git commit Recording Changes Savesthe changes made in the staging area to the repository Working Directory Staging Area Repository puts “Hello World Everybody” - Words + Everybody
  • 26.
    git commit Recording Changes Savesthe changes made in the staging area to the repository Working Directory Staging Area Repository puts “Hello World Everybody” - Words + Everybody
  • 27.
    git log History ofChanges Lists informations about commits in reverse chronological order commit ca82a6dff817ec66f44342007202690a93763949 Author: Scott Chacon <schacon@gee-mail.com> Date: Mon Mar 17 21:52:11 2008 -0700 changed the version number commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 16:40:33 2008 -0700 removed unnecessary test commit a11bef06a3f659402fe7563abf99ad00de2209e6 Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 10:31:28 2008 -0700 first commit
  • 28.
    git log History ofChanges Lists informations about commits in reverse chronological order commit ca82a6dff817ec66f44342007202690a93763949 Author: Scott Chacon <schacon@gee-mail.com> Date: Mon Mar 17 21:52:11 2008 -0700 changed the version number commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 16:40:33 2008 -0700 removed unnecessary test commit a11bef06a3f659402fe7563abf99ad00de2209e6 Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 10:31:28 2008 -0700 first commit
  • 29.
    git log -p Historyof Changes Shows differences introduced by every commit commit ca82a6dff817ec66f44342007202690a93763949 Author: Scott Chacon <schacon@gee-mail.com> Date: Mon Mar 17 21:52:11 2008 -0700 changed the version number diff --git a/Rakefile b/Rakefile index a874b73..8f94139 100644 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,7 @@ require 'rake/gempackagetask' spec = Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = "simplegit" - s.version = "0.1.0" + s.version = "0.1.1" s.author = "Scott Chacon" s.email = "schacon@gee-mail.com" s.summary = "A simple gem for using Git in Ruby code."
  • 30.
    git log -p Historyof Changes Shows differences introduced by every commit commit ca82a6dff817ec66f44342007202690a93763949 Author: Scott Chacon <schacon@gee-mail.com> Date: Mon Mar 17 21:52:11 2008 -0700 changed the version number diff --git a/Rakefile b/Rakefile index a874b73..8f94139 100644 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,7 @@ require 'rake/gempackagetask' spec = Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = "simplegit" - s.version = "0.1.0" + s.version = "0.1.1" s.author = "Scott Chacon" s.email = "schacon@gee-mail.com" s.summary = "A simple gem for using Git in Ruby code." Where What
  • 31.
    git log OPTIONS Historyof Changes --stat shows list of modified files -1 -2 -n shows last commit shows last 2 commits shows last n commits -S<string> only shows commits adding/removing <string>
  • 32.
    git commit --amend Undo takeschanges in staging area and adds them to the previous commit Working Directory Staging Area Repository list of changes
  • 33.
    git commit --amend Undo takeschanges in staging area and adds them to the previous commit Working Directory Staging Area Repository list of changes
  • 34.
    git reset HEAD<file> Undo Removes the selected file from the staging area Working Directory Staging Area Repository puts “Hello World Everybody” - Words + Everybody
  • 35.
    git reset HEAD<file> Undo Removes the selected file from the staging area Working Directory Staging Area Repository puts “Hello World Everybody”
  • 36.
    git checkout --<file> Undo Discards changes of the file in the working directory Working Directory Staging Area Repository puts “Hello World Everybody”
  • 37.
    git checkout --<file> Undo Discards changes of the file in the working directory Working Directory Staging Area Repository puts “Hello World Everybody” puts “Hello World”
  • 38.
    git push <remote_name><branch_name> Going Remote Shares the modifications with the remote repository Local Working Directory Staging Area Repository My File changes to My File Remote master branch
  • 39.
    git push <remote_name><branch_name> Going Remote Shares the modifications with the remote repository Local Working Directory Staging Area Repository My File changes to My File Remote git push master branch
  • 40.
    git fetch <remote_name> GoingRemote Retrieves data from the remote repository (do not merge) Local Working Directory Staging Area Repository My File changes to My File Remote 1 master 2 3 5 4 1 2 3 3
  • 41.
    git fetch <remote_name> GoingRemote Retrieves data from the remote repository (do not merge) Local Working Directory Staging Area Repository My File changes to My File Remote 1 master 2 3 5 4 1 2 3 3 5 4
  • 42.
    git pull Going Remote Retrievesdata from the remote repository (and merge) Local Working Directory Staging Area Repository My File changes to My File Remote 1 master 2 3 5 4 1 2 3 3
  • 43.
    git pull Going Remote Retrievesdata from the remote repository (and merge) Local Working Directory Staging Area Repository My File changes to My File Remote 1 master 2 3 5 4 1 2 3 4 5 3
  • 44.
  • 45.
    branch: you divergefrom the main line of development and continue to do work without messing with that main line
  • 46.
  • 47.
  • 48.
    master mybranch $ git branchmybranch $ git checkout mybranch
  • 49.
    master mybranch $ git branchmybranch $ git checkout mybranch $ git commit
  • 50.
    master mybranch $ git branchmybranch $ git checkout mybranch $ git commit $ git commit
  • 51.
    master mybranch $ git branchmybranch $ git checkout mybranch $ git commit $ git commit $ git checkout master
  • 52.
  • 53.
  • 54.
  • 55.
    mybranch master $ git checkoutmaster $ git merge mybranch
  • 56.
  • 57.
  • 58.
  • 59.
    wants you tobranch&merge