L E V E L 1 L E V E L 1
L E V E L 1 L E V E L 1
S A M E O L D S T O R Y
S A M E O L D S T O R Y
C
C
o
o
l
l
l
l
a
a
b
b
o
o
r
r
a
a
t
t
i
i
o
o
n
n
I
V E R S I O N C O N T R O L S Y S T E M S
Mer gi n g
R E P O S I T O R Y L O C A T I O N S
D I S T R I B U T E D V E R S I O N C O N T R O L S Y S T E M
Git is a
O R I G I N S
•
Linux Kernel project.
• Meant to be distributed, fast and more natural.
• Capable of handling large projects.
W O R K I N G W I T H G I T
•
Command line interface
• O
!
cial Git Site —
st ar t her e
http://git-scm.com/
• Many GUI tools available
G I T H E L P
$ git help
usage: git [--version] [--exec-path[=<path>]] [--html-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug ...
GIT-CONFIG(1) Git Manual GIT-CONFIG(1)
NAME
git-config - Get and set repository or global options SYNOPSIS
git config [<file-option>] [type] [-z|--null] name [value [value_regex]] git config [<file-option>] [type] --add name value
...
$ git help config
G I T H E L P
S E T T I N G U P G I T
Pretty command line colors
Who gets credit for changes
What email you use
$ git config --global user.name "Gregg Pollack"$ git config --global user.email [email protected] $ git config --global color.ui true
S T A R T I N G A R E P O
git metadata is stored here
$ mkdir store $ cd store $ git init
G I T W O R K F L O W
Jane creates README.txt
"
le
Add
"
le to staging area
Commit changes
Getting ready to take a picture
A snapshot of those on the stage
Starts as untracked
Commit changes
Commit changes
G I T W O R K F L O W
G I T W O R K F L O W
Jane creates README.txt
Jane creates README.txt
"
"
le
le
Add
Add
"
"
le to staging area
le to staging area
Jane modi
Jane modi
"
"
es README.txt
es README.txt
"
"
le & adds LICENSE
le & adds LICENSE
Add both
Add both
"
"
les to staging area
les to staging area
Commit changes
# On branch master # On branch master # # # Initial commit # Initial commit # # # Untracked files: # Untracked files: #
# (use (use "git "git add add <file>..." <file>..." to to include include in in what what will will be be committed)committed)
#
#
#
# README.txtREADME.txt
nothing added to commit but untracked files present (use "git add" to track)
nothing added to commit but untracked files present (use "git add" to track)
Our newly created file
Our newly created file
Jane creates README.txt
Jane creates README.txt
"
"
le
le
$
Our staged file
Our staged file
$
$ git add README.txt git add README.txt
git status git status $ $ # On branch master # On branch master # # # Initial commit # Initial commit # # # Changes to be committed: # Changes to be committed: #
# (use (use "git "git rm rm --cached --cached <file>..." <file>..." to to unstage)unstage)
#
#
#
# new new file: file: README.txtREADME.txt
#
#
Add
$ git commit -m "Create a README." [master abe28da] Create a README.
1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 README.txt
Commit changes
$ git status
# On branch master
nothing to commit (working directory clean)
No new or modified files since last commit
Commit message
what work was done?
timeline
# On branch master
# Changed but not updated: # # modified: README.txt # # Untracked files: # # LICENSE
no changes added to commit $ git status
Jane modi
"
es README.txt
"
le & adds LICENSE
$ git add README.txt LICENSE
$ git add --all
Add both
"
les to staging area
Adds all new or modified files
OR
# On branch master
# Changes to be committed: #
# new file: LICENSE # modified: README.txt #
$ git status
$ git commit -m "Add LICENSE and finish README." [master 1b0019c] Add LICENSE and finish README. 2 files changed, 21 insertions(+), 0 deletions(-) create mode 100644 LICENSE
G I T T I M E L I N E H I S T O R Y
commit 1b0019c37e3f3724fb2e9035e6bab4d7d87bf455 Author: Gregg Pollack <[email protected]>
Date: Thu Jul 5 22:31:27 2012 -0400 Add LICENSE and finish README.
commit 5acaf86b04aaf9cbbb8ebb9042a20a46d0b9ce76 Author: Gregg Pollack <[email protected]>
Date: Thu Jul 5 22:00:46 2012 -0400 Create a README.
D I F F E R E N T W A Y S T O A D D
$ git add <list of files> $ git add --all
$ git add *.txt
Add all txt files in current directory
$ git add docs/*.txtAdd all txt files in docs directory
$ git add docs/Add all files in docs directory
$ git add "*.txt"Add all txt files in the whole project
Add the list of files
Add all files
S T A G I N G & R E M O T E S
G I T D I F F
LICENSE
Copyright (c) 2012 Envy Labs LLC ...
Permission is hereby granted, free of charge, to any person obtaining a copy
LICENSE
Copyright (c) 2012 Code School LLC ...
Permission is hereby granted, free of charge, to any person obtaining a copy
diff --git a/LICENSE b/LICENSE
index 7e4922d..442669e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2012 Envy Labs LLC
+Copyright (c) 2012 Code School LLC
edit
Show unstaged differences since last commit
Line removed
Line added
V I E W I N G S T A G E D D I F F E R E N C E S
$ git add LICENSE
$ git diff
$
No differences, since all changes are staged
git diff --staged
View staged differences
diff --git a/LICENSE b/LICENSE
index 7e4922d..442669e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2012 Envy Labs LLC
+Copyright (c) 2012 Code School LLC
# On branch master
# Changes to be committed:
#
(use "git reset HEAD <file>..." to unstage)
#
# modified:
LICENSE
#
HEAD
U N S T A G I N G F I L E S
$ git status
$
Unstage Tip
git reset HEAD LICENSE
Refers to last commit
Unstaged changes after reset:
M LICENSE
D I S C A R D C H A N G E S
$
Blow away all changes
since last commit
git status
$ git checkout -- LICENSE
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory) #
# modified: LICENSE #
$ git status
HEAD
S K I P S T A G I N G A N D C O M M I T
Readme.txt
here is my readme and now I can sleep
Readme.txt
edit
Add changes from all tracked files
Doesn’t add new (untracked) files
here is my readme the cake is a lie
$ git commit -a -m "Modify readme"
[master d00fefc] Modify readme
1 files changed, 1 insertions(+), 1 deletions(-)
U N D O I N G A C O M M I T
# On branch master
# Changes to be committed:
#
(use "git reset HEAD <file>..." to unstage)
#
# modified:
README.txt
#
$ git reset --soft HEAD^
git status
$
Reset into staging
Move to commit before ‘HEAD’
Now I can make changes, and re-commit
Whoops, we forgot something on that commit.
master
A D D I N G T O A C O M M I T
[master fe98ef9] Modify readme and add todo.txt.
2 files changed, 2 insertions(+), 1 deletions(-)
create mode 100644 todo.txt
$ git add todo.txt
$
Add to the last commit
New commit message
Maybe we forgot to add a
!
le
git commit --amend -m "Modify readme & add todo.txt."
Whatever has been staged is added to last commit
master
U S E F U L C O M M A N D S
$ git reset --soft HEAD^
Undo last commit, put changes into staging
git reset --hard HEAD^
Undo last commit and all changes
$
git commit --amend -m "New Message"
Change the last commit
$
git reset --hard HEAD^^
Undo last 2 commits and all changes
$
H O W T O S H A R E ?
Git doesn’t take care of access control
“git remote” command
p us h
p u l l
p u l l
Remote Repository
R E M O T E R E P O S I T O R Y H O S T I N G
•
GitHub
•BitBucket
• Gitosis
• Gitorious
Hosted
Self Managed
p us h
master
A D D I N G A R E M O T E
New remote
our name for this remote
address
$ git remote add origin https://github.com/Gregg/git-real.git
$ git remote -v
origin https://github.com/Gregg/git-real.git (fetch)
origin https://github.com/Gregg/git-real.git (push)
show remote repositories
P U S H I N G T O R E M O T E
$ git push -u origin master
remote repository name
local branch to push
Username for 'https://github.com': GreggPassword for 'https://[email protected]': Counting objects: 11, done.
Delta compression using up to 4 threads. Compressing objects: 100% (6/6), done.
Writing objects: 100% (11/11), 1.50 KiB, done. Total 11 (delta 0), reused 0 (delta 0)
To https://github.com/Gregg/git-real.git * [new branch] master -> master
https://help.github.com/articles/set-up-git
Password caching
p us h
master
P U L L I N G F R O M R E M O T E
$ git pull
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 1), reused 3 (delta 1)
Unpacking objects: 100% (3/3), done.
From https://github.com/Gregg/git-real
fe98ef9..4e67ded
master
-> origin/master
Updating fe98ef9..4e67ded
Fast-forw
ard
todo.txt | 1 +
1 file changed, 1 insertion(+)
To pull changes down from the remote
p u l l
origin
I t ’s g o od t o
d o t h is o f t
e n
H A V I N G M U L T I P L E R E M O T E S
origin
production
W O R K I N G W I T H R E M O T E S
$ git remote add <name> <address>
$ git remote rm <name>
To add new remotes
To remove remotes
$ git push -u <name> <branch>
To push to remotes
H E R O K U R E M O T E
$ heroku create
$ git push heroku master
Creating dev-server-1426... done, stack is cedar
http://dev-server-1426.herokuapp.com/ | [email protected]: dev-server-1426.git Git remote heroku added
git repo ssh address
triggers deploy
$ git remote -vheroku [email protected]: dev-server-1426.git (fetch) heroku [email protected]: dev-server-1426.git (push) origin https://github.com/Gregg/git-real.git (fetch) origin https://github.com/Gregg/git-real.git (push)
U S E F U L C O M M A N D S
$ git reset --soft HEAD^
Don’t d o these af ter you push
git reset --hard HEAD^
$
git commit --amend -m "New Message"
$
git reset --hard HEAD^^
$
L E V E L 3
C O L L A B O R A T I N G
C O L L A B O R A T I N G
push
push
github
github
How do we start collaborating?
How do we start collaborating?
J
J
a
a
n
n
e
e
G
G
r
r
e
e
g
g
g
g
“I want a copy”
“I want a copy”
“Clone the repo!”
“Clone the repo!”
local repo local repo
?
F I N D I N G T H E R E P O U R L
F I N D I N G T H E R E P O U R L
C L O N I N G A R E P O S I T O R Y
$ git clone https://github.com/codeschool/git-real.git
Cloning into '
git-real'...
URL of the remote repository
$ git clone https://github.com/codeschool/git-real.git
git-demoCloning into '
git-demo'...
origin https://github.com/codeschool/git-real.git (fetch)
origin https://github.com/codeschool/git-real.git (push)
G I T C L O N E
HEAD
master
1
- Downloads the entire repository into a new git-real directory.
2- Adds the ‘origin’ remote, pointing it to the clone URL.
3