SlideShare ist ein Scribd-Unternehmen logo
1 von 156
Downloaden Sie, um offline zu lesen
GIT BASICS
L E V E L 1
L E V E L 1 — G I T B A S I C S
SAME OLD STORY
Collaboration Issues!
VERSION CONTROL SYSTEMS
Merging
Time Capsule
L E V E L 1 — G I T B A S I C S
REPOSITORY LOCATIONS
Central Repository Distributed Repository
DISTRIBUTED VERSION CONTROL SYSTEM
Git is a
(DVCS)
L E V E L 1 — G I T B A S I C S
ORIGINS
• Linux Kernel project.
• Meant to be distributed, fast and more natural.
• Capable of handling large projects.
L E V E L 1 — G I T B A S I C S
WORKING WITH GIT
• Command line interface
• Official Git Site —
start here
http://git-scm.com/
• Many GUI tools available
L E V E L 1 — G I T B A S I C S
GIT HELP
$ 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
L E V E L 1 — G I T B A S I C S
GIT HELP
pass in any git command
L E V E L 1 — G I T B A S I C S
SETTING UP GIT
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 gregg@codeschool.com
$ git config --global color.ui true
L E V E L 1 — G I T B A S I C S
STARTING A REPO
git metadata is stored here
$ mkdir store
$ cd store
$ git init
Initialized empty Git repository in /Users/gregg/store/.git/
L E V E L 1 — G I T B A S I C S
GIT WORK FLOW
Jane creates README.txt file
Add file to staging area
Commit changes
Getting ready to take a picture
A snapshot of those on the stage
Starts as untracked
Commit changes
L E V E L 1 — G I T B A S I C S
GIT WORK FLOW
Jane creates README.txt file
Add file to staging area
Jane modifies README.txt file & adds LICENSE
Add both files to staging area
Commit changes
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README.txt
nothing added to commit but untracked files present (use "git add" to track)
L E V E L 1 — G I T B A S I C S
Our newly created file
Jane creates README.txt file
$ git status To check what’s changed since last commit
L E V E L 1 — G I T B A S I C S
Our staged file
$ git add README.txt
git status$
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: README.txt
#
Add file to staging area
L E V E L 1 — G I T B A S I C S
$ 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
master
L E V E L 1 — G I T B A S I C S
# On branch master
# Changed but not updated:
#
# modified: README.txt
#
# Untracked files:
#
# LICENSE
no changes added to commit
$ git status
Jane modifies README.txt file & adds LICENSE
master
L E V E L 1 — G I T B A S I C S
$ git add README.txt LICENSE
$ git add --all
Add both files 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
master
L E V E L 1 — G I T B A S I C S
$ 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
Commit changes master
L E V E L 1 — G I T B A S I C S
GIT TIMELINE HISTORY
commit 1b0019c37e3f3724fb2e9035e6bab4d7d87bf455
Author: Gregg Pollack <gregg@codeschool.com>
Date: Thu Jul 5 22:31:27 2012 -0400
Add LICENSE and finish README.
commit 5acaf86b04aaf9cbbb8ebb9042a20a46d0b9ce76
Author: Gregg Pollack <gregg@codeschool.com>
Date: Thu Jul 5 22:00:46 2012 -0400
Create a README.
$ git log
master
L E V E L 1 — G I T B A S I C S
DIFFERENT WAYS TO ADD
$ git add <list of files>
$ git add --all
$ git add *.txt Add all txt files in current directory
$ git add docs/*.txt Add 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
STAGING & REMOTES
L E V E L 2
GIT DIFF
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
$ git diff
VIEWING STAGED DIFFERENCES
$ 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
L E V E L 2 — S T A G I N G & R E M O T E S
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: LICENSE
#
HEAD
UNSTAGING FILES
$ git status
$
Unstage Tip
git reset HEAD LICENSE
Refers to last commit
Unstaged changes after reset:
M LICENSE
L E V E L 2 — S T A G I N G & R E M O T E S
master
DISCARD CHANGES
$
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
L E V E L 2 — S T A G I N G & R E M O T E S
nothing to commit (working directory clean)
HEAD
SKIP STAGING AND COMMIT
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(-)
L E V E L 2 — S T A G I N G & R E M O T E S
master
UNDOING A COMMIT
# 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.
L E V E L 2 — S T A G I N G & R E M O T E S
master
HEAD
ADDING TO A COMMIT
[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 file
git commit --amend -m "Modify readme & add todo.txt."
Whatever has been staged is added to last commit
L E V E L 2 — S T A G I N G & R E M O T E S
master
HEAD
USEFUL COMMANDS
$ 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$
L E V E L 2 — S T A G I N G & R E M O T E S
HOW TO SHARE?
Git doesn’t take care of access control
“git remote” command
L E V E L 2 — S T A G I N G & R E M O T E S
push
pull
pull
Remote Repository
master
REMOTE REPOSITORY HOSTING
• GitHub
• BitBucket
• Gitosis
• Gitorious
Hosted Self Managed
L E V E L 2 — S T A G I N G & R E M O T E S
push
master
L E V E L 2 - S T A G I N G & R E M O T E S
L E V E L 2 - S T A G I N G & R E M O T E S
ADDING A REMOTE
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
L E V E L 2 — S T A G I N G & R E M O T E S
origin
PUSHING TO REMOTE
$ git push -u origin master
remote repository name local branch to push
Username for 'https://github.com': Gregg
Password for 'https://Gregg@github.com':
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-gitPassword caching
push
master
origin
L E V E L 2 - S T A G I N G & R E M O T E S
L E V E L 2 - S T A G I N G & R E M O T E S
Same information from “git log”
PULLING FROM REMOTE
$ 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-forward
todo.txt | 1 +
1 file changed, 1 insertion(+)
To pull changes down from the remote
L E V E L 2 — S T A G I N G & R E M O T E S
pull
origin
It’s good to do this often
HAVING MULTIPLE REMOTES
L E V E L 2 — S T A G I N G & R E M O T E S
origin production
test
WORKING WITH REMOTES
$ 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
usually master
L E V E L 2 — S T A G I N G & R E M O T E S
HEROKU REMOTE
$ heroku create
$ git push heroku master
Creating dev-server-1426... done, stack is cedar
http://dev-server-1426.herokuapp.com/ | git@heroku.com: dev-server-1426.git
Git remote heroku added
git repo ssh address
triggers deploy
$ git remote -v
heroku git@heroku.com: dev-server-1426.git (fetch)
heroku git@heroku.com: dev-server-1426.git (push)
origin https://github.com/Gregg/git-real.git (fetch)
origin https://github.com/Gregg/git-real.git (push)
To push to heroku
L E V E L 2 — S T A G I N G & R E M O T E S
USEFUL COMMANDS
$ git reset --soft HEAD^
Don’t do these after you push
git reset --hard HEAD^$
git commit --amend -m "New Message"$
git reset --hard HEAD^^$
L E V E L 2 — S T A G I N G & R E M O T E S
CLONING & BRANCHING
L E V E L 3
COLLABORATING
L E V E L 3 — C L O N I N G & B R A N C H I N G
push
github
How do we start collaborating?
JaneGregg
“I want a copy”
“Clone the repo!”
local repo
?
FINDING THE REPO URL
URL of the remote repository
L E V E L 3 — C L O N I N G & B R A N C H I N G
FINDING THE REPO URL
URL of the remote repository
L E V E L 3 — C L O N I N G & B R A N C H I N G
CLONING A REPOSITORY
$ 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-demo
Cloning into 'git-demo'...
local folder name
L E V E L 3 — C L O N I N G & B R A N C H I N G
origin https://github.com/codeschool/git-real.git (fetch)
origin https://github.com/codeschool/git-real.git (push)
GIT CLONE
HEAD
master1 - Downloads the entire repository into a new git-real directory.
2 - Adds the ‘origin’ remote, pointing it to the clone URL.
3 - Checks out initial branch (likely master).
$ git remote -v
sets the head
L E V E L 3 — C L O N I N G & B R A N C H I N G
Need to work on a feature that will take some time?
BRANCHING OUT
master
cat
branch created from master
Jane
$ git branch cat
HEAD
$ git branch
cat
* master
HEAD still on master
Time to branch out.
L E V E L 3 — C L O N I N G & B R A N C H I N G
SWITCHING TO A BRANCH
HEAD
Time to jump on that new 'cat' branch.
HEAD is now on ‘cat’
master
$ git checkout cat
Switched to branch 'cat'
cat
Jane
L E V E L 3 — C L O N I N G & B R A N C H I N G
master
cat
WORKING ON A BRANCH
HEAD
committed to the
“cat” branch
$ echo "Schrödinger" > cat.txt
$ git add cat.txt
$ git commit -m "Create quantum cat."
[cat ab48a3f] Create quantum cat.
1 file changed, 1 insertion(+)
create mode 100644 cat.txt
L E V E L 3 — C L O N I N G & B R A N C H I N G
README.txt cat.txt
master
cat
WORKING ON A BRANCH
HEAD
$ ls
see the cat?
L E V E L 3 — C L O N I N G & B R A N C H I N G
commit 1191ceb7252c9d4b1e05c9969a55766a8adfce3b
Author: Gregg <gregg@codeschool.com>
Date: Wed Jun 27 23:11:20 2012 -0700
Add README.
master
cat
BACK TO MASTER
$ git checkout master
HEAD
and we’re back on master
cat.txt is gone!
$ git log
nothing in the log either
Switched to branch 'master'
$ ls
README.txt
L E V E L 3 — C L O N I N G & B R A N C H I N G
README.txt cat.txt
master
cat
BACK TO CAT
$ git checkout cat
HEADphew, still here
Switched to branch 'cat'
$ ls
L E V E L 3 — C L O N I N G & B R A N C H I N G
cat
TIME TO MERGE
Done with that feature branch?
master
$ git merge cat
HEAD
merge brings one branch’s changes into another
what’s that?
$ git checkout master
Switched to branch 'master'
$ ls
README.txt
Updating 1191ceb..ab48a3f
Fast-forward
cat.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 cat.txt
Time to merge it into 'master '.
no cat, as expected
cat
FAST-FORWARD TO THE FUTURE
master
HEAD
nothing new something new
Conditions for a fast-forward merge
L E V E L 3 — C L O N I N G & B R A N C H I N G
cat
BRANCH CLEAN UP
When you’re done with a branch, you can safely remove it.
master
HEAD
$ git branch -d cat
Deleted branch cat (was 957dbff).
L E V E L 3 — C L O N I N G & B R A N C H I N G
admin
NON-FAST-FORWARD
master
Let’s work on a new admin feature.
$ git checkout -b admin
HEAD
creates and checks out branch
“Please fix the bugs on master.”
Switched to a new branch 'admin'
...
$ git add admin/dashboard.html
$ git commit -m 'Add dashboard'
...
$ git add admin/users.html
$ git commit -m 'Add user admin'
L E V E L 3 — C L O N I N G & B R A N C H I N G
admin
BUG FIXING ON MASTER
master$ git checkout master
HEAD
Switched to branch 'master'
Time to put out the fire. We’ll get back to that admin branch later.
$ git branch
admin
* master
$ git pull
...
$ git add store.rb
$ git commit -m 'Fix store bug'
...
$ git add product.rb
$ git commit -m 'Fix product'
...
$ git push
HEAD
admin
BACK TO OUR BRANCH
master
$ git checkout admin
HEAD
$ git checkout master
When ready to bring in changes
Switched to branch 'admin'
...
Switched to branch 'admin'
$ git merge admin
HEAD
L E V E L 3 — C L O N I N G & B R A N C H I N G
1 Merge branch 'admin'
2
3 # Please enter a commit message to explain why this merge is necessary,
4 # especially if it merges an updated upstream into a topic branch.
5 #
6 # Lines starting with '#' will be ignored, and an empty message aborts
7 # the commit.
AND SUDDENLY...
Git uses Vi if no default editor is set to edit commit messages.
+ hit Enter to write (save) & quit
h left l right
j down k up ESC leave mode
i insert mode
:wq save & quit
:q! cancel & quit
Vi commands
DON’T PANIC
:wq
Merge made by the 'recursive' strategy.
0 files changed
create mode 100644 admin/dashboard.html
create mode 100644 admin/users.html admin
RECURSIVE MERGING
master
2 commits
2 commits
Git can’t fast-forward since changes were made in both branches.
merge commit
$ git log
A commit was created to merge the two branches.
commit 19f735c3556129279bb10a0d1447dc5aba1e1fa9
Merge: 5c9ed90 7980856
Author: Jane <Jane@CodeSchool.com>
Date: Thu Jul 12 17:51:53 2012 -0400
Merge branch 'admin'
COLLABORATION BASICS
L E V E L 4
push
github
?
I want a copy
JaneGregg
$ git clone https://github.com/codeschool/git-real.git
Clone the repo
Start making changes
Jane adds two files
TWO NEW FILES
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# product.rb
# store.rb
nothing added to commit but untracked files present
jane $ git commit -m "Add store and product models."
jane $ git status
[master 30ce481] Add product and store models.
2 files changed, 2 insertions(+)
create mode 100644 product.rb
create mode 100644 store.rb
jane $ git add --all
COMMIT FLOW
L E V E L 4 — C O L L A B O R A T I O N B A S I C S
Sends her new commitjane $ git push
Counting objects: 5, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 441 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://github.com/codeschool/git-real.git
4e67ded..30ce481 master -> master
push new commits
master
github
DIFFERENT GIT COMMITS
L E V E L 4 — C O L L A B O R A T I O N B A S I C S
same
different
gregg github
What happens now?
gregg $ git commit -am "Update the readme."
[master c715339] Update the readme.
1 file changed, 1 insertion(+), 1 deletion(-)
GIT PUSH REJECTED
L E V E L 4 — C O L L A B O R A T I O N B A S I C S
Cannot write over Jane’s commitgregg $ git push
To https://github.com/codeschool/git-real.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/codeschool/git-real.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull
$ git push
...
...
Success!
UNDERSTANDING PULL
$ git pull
1. Fetch (or Sync) our local repository with the remote one
origin
gregg github
$ git fetch
Fetch doesn’t actually update any of our local code
UNDERSTANDING PULL
$ git pull
1. Fetch (or Sync) our local repository with the remote one
mastermaster origin/master
gregg github
2. Merges the origin/master with master $ git merge origin/master
$ git fetch
MERGE COMMIT
$ git pull
1. Fetch (or Sync) our local repository with the remote one
2. Merges the origin/master with master
1 Merge branch 'master' of https://github.com/codeschool/git-real
2
3 # Please enter a commit message to explain why this merge is necessary,
4 # especially if it merges an updated upstream into a topic branch.
5 #
6 # Lines starting with '#' will be ignored, and an empty message aborts
7 # the commit.
Create a new commit for this merge my editor
$ git merge origin/master
GIT PUSH REJECTED
$ git pull
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 0), reused 4 (delta 0)
Unpacking objects: 100% (4/4), done.
From https://github.com/codeschool/git-real
4e67ded..30ce481 master -> origin/master
Merge made by the 'recursive' strategy.
product.rb | 1 +
store.rb | 1 +
2 files changed, 2 insertions(+)
create mode 100644 product.rb
create mode 100644 store.rb
merge commit
MERGE COMMIT
$ git pull
1. Fetch (or Sync) our local repository with the remote one
master
origin/master
2. Merges the origin/master with master
merge commit
$ git fetch
$ git merge origin/master
PUSHING COMMITS
$ git push
Update origin/master be at the same state as our local repo
master
origin/master
merge commit
github
OUR LOG
The problem with pullgregg $ git log
commit ee47baaedcd54e1957f86bda1aaa1b8a136185da
Merge: 87c5243 57501d5
Author: Gregg Pollack <Gregg@CodeSchool.com>
Merge branch 'master' of https://github.com/Gregg/git-real
commit 87c5243d2266f05cd9fda8b1c9137f11b3fe6f31
Author: Gregg Pollack <Gregg@CodeSchool.com>
Update the readme.
commit 57501d595b16e2d1198a9c04c547a5b1380a6618
Author: Gregg Pollack <Gregg@CodeSchool.com>
Add store and product models.
MERGE CONFLICTS
README
here is my readme
the cake is a lie
README
here is my readme
the cake is telling the truth!
JaneGregg
same
different
gregg github
committed committed & pushed
MERGE CONFLICT
L E V E L 4 — C O L L A B O R A T I O N B A S I C S
gregg $ 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
ee47baa..4e76d35 master -> origin/master
Auto-merging README.txt
CONFLICT (content): Merge conflict in README.txt
Automatic merge failed; fix conflicts and then commit the result.
Git modified this file with the diff
MERGE CONFLICT
L E V E L 4 — C O L L A B O R A T I O N B A S I C S
gregg $ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 1 different commit each, respectively.
#
# Unmerged paths:
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: README.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
Need to edit these files
MERGE CONFLICT
L E V E L 4 — C O L L A B O R A T I O N B A S I C S
gregg $ git commit -a
README
here is my readme
<<<<<<< HEAD
the cake is a lie.
=======
the cake is telling the truth!
>>>>>>>
4e76d3542a7eee02ec516a47600002a90a4e4b48
here is my readme
the cake is a lie.Our local version
Jane’s version
Edit file and correct
Merge commit
COMMIT EDITOR
gregg $ git commit -a
1 Merge branch 'master' of https://github.com/Gregg/git-real
2
3 Conflicts:
4 ▸ README.txt
5 #
6 # It looks like you may be committing a merge.
7 # If this is not correct, please remove the file
8 #▸.git/MERGE_HEAD
9 # and try again.
10
11
12 # Please enter the commit message for your changes. Lines starting
13 # with '#' will be ignored, and an empty message aborts the commit.
14 # On branch master
15 # Your branch and 'origin/master' have diverged,
16 # and have 1 and 1 different commit each, respectively.
EditorMerge commit
MERGE COMMIT
master
origin/master
Merge commit master
origin/master
Merge commit
$ git push
COLLABORATION BASICS
L E V E L 4
REMOTE BRANCHES & TAGS
L E V E L 5
WHY CREATE A REMOTE BRANCH?
• When you need other people to work on your branch.
Gregg
• Any branch that will last more than a day.
L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
CREATING A REMOTE BRANCH
$ git checkout -b shopping_cart
Switched to a new branch 'shopping_cart'
$ git push origin shopping_cart
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 619 bytes, done.
Total 6 (delta 2), reused 0 (delta 0)
To https://github.com/codeschool/git-real.git
* [new branch] shopping_cart -> shopping_cart
Links local branch to
the remote branch
(tracking)
L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
PUSHING TO THE BRANCH
$ git add cart.rb
$ git commit -a -m "Add basic cart ability."
[shopping_cart 2a0dbf9] Add basic cart ability
1 file changed, 1 insertion(+)
create mode 100644 cart.rb
Pushed changes from branch$ git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 302 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To https://github.com/codeschool/git-real.git
786d7a1..2a0dbf9 shopping_cart -> shopping_cart
CREATING A BRANCH
Hey Jane, I started a branch
Sweet, I’ll check it out
L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
PULLING NEW BRANCHES
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 9 (delta 3), reused 8 (delta 2)
Unpacking objects: 100% (9/9), done.
From https://github.com/Gregg/git-real
4e76d35..786d7a1 master -> origin/master
* [new branch] shopping_cart -> origin/shopping_cart
Updating 4e76d35..786d7a1
Fast-forward
README.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
remote branch
$ git pull
L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
PULLING NEW BRANCHES
list all remote branches
Now we can contribute and push!
$ git branch
* master
$ git branch -r
origin/master
origin/shopping_cart
$ git checkout shopping_cart
Branch shopping_cart set up to track remote branch shopping_cart from origin.
Switched to a new branch 'shopping_cart'
$ git branch
master
* shopping_cart
L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
REMOTE SHOW
$ git remote show origin
* remote origin
Fetch URL: https://github.com/Gregg/git-real.git
Push URL: https://github.com/Gregg/git-real.git
HEAD branch: master
Remote branches:
master tracked
shopping_cart tracked
Local branches configured for 'git pull':
master merges with remote master
shopping_cart merges with remote shopping_cart
Local refs configured for 'git push':
master pushes to master (up to date)
shopping_cart pushes to shopping_cart (local out of date)
REMOVING A BRANCH
Must delete local branch manually
$ git push origin :shopping_cart
To https://github.com/codeschool/git-real.git
- [deleted] shopping_cart
$ git branch -d shopping_cart
error: The branch 'shopping_cart' is not fully merged.
If you are sure you want to delete it, run 'git branch -D shopping_cart'.
git branch -D shopping_cart
Deleted branch shopping_cart (was ea0a1b9).
$
Deletes remote branch
L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
WHAT ABOUT GREGG?
L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
GreggJane
ON DELETED REMOTE BRANCH
No remote to push to (it’s just a local branch now)
$ git commit -m -a "Add ability to pay."
[shopping_cart 9851887] Add ability to pay.
1 file changed, 1 insertion(+), 1 deletion(-)
$ git push
Everything up-to-date
git remote show origin$
Gregg
Remote branches:
master tracked
refs/remotes/origin/shopping_cart stale (use 'git remote prune' to remove)
git remote prune origin$
Pruning origin
URL: https://github.com/codeschool/git-real.git
* [pruned] origin/shopping_cart
To clean up deleted remote branches
REMOTE BRANCH NAMES
$ git branch
Heroku deploys only master branch
Would not work, would push to staging
heroku-staging
* staging
master
$ git push heroku-staging staging
$ git push heroku-staging staging:master
Will push and deploy staging on heroku
local:remote
L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
TAGGING
v0.0.1
v0.0.2
A tag is a reference to a commit (used mostly for release versioning)
Text
$ git tag
$ git checkout v0.0.1
list all tags
check out code at commit
$ git tag -a v0.0.3 -m "version 0.0.3"
To add a new tag
$ git push --tags
To push new tags
L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
REMOTE BRANCHES & TAGS
L E V E L 5
REBASE BELONG TO US
L E V E L 6
L E V E L 6 — R E B A S E B E L O N G T O U S
MERGE COMMITS ARE BAD
master
origin/master
merge commit
Add product and store models.
Update the Readme.
Merge branch 'master' of http...
Add Cats.
Merge branch 'cats'
Merge commits feel useless
DIFFERENT GIT COMMITS
same
different
gregg github
Jane’s commit
gregg $ git commit -am "Update the readme."
[master c715339] Update the readme.
1 file changed, 1 insertion(+), 1 deletion(-)
L E V E L 6 — R E B A S E B E L O N G T O U S
L E V E L 6 — R E B A S E B E L O N G T O U S
GIT PUSH REJECTED
Cannot write over Jane’s commitgregg $ git push
To https://github.com/codeschool/git-real.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/codeschool/git-real.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull
$ git push
...
...
Nope!
L E V E L 6 — R E B A S E B E L O N G T O U S
FETCH
gregg $ git fetch
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 0), reused 4 (delta 0)
Unpacking objects: 100% (4/4), done.
From https://github.com/codeschool/git-real
f35f2f1..71a4650 master -> origin/master
Syncs
gregg github
but doesn’t merge
master origin/master
L E V E L 6 — R E B A S E B E L O N G T O U S
REBASE
gregg $ git rebase
master origin/master
1. Move all changes to master which are not in origin/master to a temporary area.
temp
L E V E L 6 — R E B A S E B E L O N G T O U S
REBASE
gregg $ git rebase
1. Move all changes to master which are not in origin/master to a temporary area.
2. Run all origin/master commits.
3. Run all commits in the temporary area, one at a time.
temp master origin/master
gregg $ git rebase
master
1. Move all changes to master which are not in origin/master to a temporary area.
2. Run all origin/master commits.
3. Run all commits in the temporary area, one at a time.
Add product and store models.
Update the Readme.
No Merge Commit!
REBASE
admin
LOCAL BRANCH REBASE
master
$ git checkout admin
Switched to branch 'admin'
admin
master
Rebase
$ git rebase master
...
IF ALL GOES WELL, MERGE MASTER
$ git checkout master
Switched to branch 'master'
admin
master
$ git merge admin
...
WHAT ABOUT CONFLICTS
same
gregg github
Add lie to readme.
Add product and store models.
Add truth to readme.Add shopping cart.
L E V E L 6 — R E B A S E B E L O N G T O U S
Edited same file!
L E V E L 6 — R E B A S E B E L O N G T O U S
FETCH
gregg $ git fetch
master origin/master
Add lie to readme. Add product and store models.
Add truth to readme.Add shopping cart.
gregg $ git rebase
1. Move all changes to master which are not in origin/master to a temporary area
temp
REBASE
origin/master
Add product and store models.
Add truth to readme.
master
gregg $ git rebase
master
2. Run all origin/master commits.
Add lie to readme.
Add shopping cart.
3. Run all commits in the temporary area, one at a time.
REBASE
temp
Add product and store models.
Add truth to readme.
gregg $ git rebase
First, rewinding head to replay your work on top of it...
Applying: Add lie to readme.
Using index info to reconstruct a base tree...
M README.txt
<stdin>:13: trailing whitespace.
the cake is a lie, and I am your father!
warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging README.txt
CONFLICT (content): Merge conflict in README.txt
Failed to merge in the changes.
Patch failed at 0001 Add lie to readme.
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort".
master
CONFLICT
REBASE CONFLICT
gregg $ git status
# Not currently on any branch.
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: README.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
Edit the README.txt
gregg $ git add README.txt
gregg $ git rebase --continue
Applying: Add lie to readme.
Applying: Add shopping cart
gregg $
REBASE CONFLICT
master
REBASED LOG
master
Add lie to readme.
Add product and store models.
Add truth to readme.
Add shopping cart.
REBASE BELONG TO US
L E V E L 6
HISTORY & CONFIGURATION
L E V E L 7
$ git log
VIEWING THE LOG
SHA hash
commit message
commit 915f242e262052b11c511dc07bef237fabb7ed85
Author: Gregg <gregg@codeschool.com>
Date: Thu Jun 28 02:10:57 2012 -0700
Update index.
COLORIZING THE LOG
$ git config --global color.ui true
$ git log --pretty=oneline
$ git log
commit 915f242e262052b11c511dc07bef237fabb7ed85
Author: Gregg <gregg@codeschool.com>
Date: Thu Jun 28 02:10:57 2012 -0700
Update index
08f202691c67abd12eb886b587ac7b26d51005c7 Update index
LOG FORMAT
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
$ git log --pretty=format:"%h %ad- %s [%an]"
any string you want
& placeholder data
placeholder replaced with
%ad author date
%an author name
%h SHA hash
%s subject
%d ref names
run “git help log” for more options!
$ git log --oneline -p
PATCH
3ea7f70 I'm telling you, it's 'Octopi'.
diff --git a/index.html b/index.html
index 021a54e..640d66d 100644
--- a/index.html
+++ b/index.html
@@ -8,7 +8,7 @@
<nav>
<ul>
<li><a href="cat.html">Cats</a></li>
- <li><a href="octopus.html">Octopuses</a></li>
+ <li><a href="octopi.html">Octopi</a></li>
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
$ git log --oneline --stat
STATS
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
3ea7f70 I'm telling you, it's 'Octopi'.
index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
96776a4 Add index.
index.html | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
* 30b1f8f Merge branch 'bird' into master
|
| * 8b8f950 Revise silly hipster name for bird aisle.
* | 915f242 Add emphasis.
|/
* 69728cd Update index descriptions.
$ git log --oneline --graph
GRAPH
visual representation of the branch merging into master
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
until
DATE RANGES
$ git log --until=1.minute.ago
since (days)$ git log --since=1.day.ago
since (hours)$ git log --since=1.hour.ago
since & until (relative)$ git log --since=1.month.ago --until=2.weeks.ago
since & until (absolute)$ git log --since=2000-01-01 --until=2012-12-21
diff --git a/index.html b/index.html
@@ -8,7 +8,10 @@
<nav>
<ul>
<li><a href="cat.html">Cats</a></li>
- <li><a href="octopus.html">Octopuses</a></li>
+ <li><a href="birds.html">Birds</a></li>
+ <li><a href="hamsters.html">Hamsters</a></li>
</ul>
</nav>
</body>
$ git diff
removed line
DIFFS
added lines
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
diff --git a/index.html b/index.html
index 021a54e..1ceb9d6 100644
@@ -8,7 +8,10 @@
<ul>
<li><a href="cat.html">Cats</a></li>
...
diff --git a/octopus.html b/octopus.html
index 55806be..ce8a2c7 100644
@@ -2,6 +2,6 @@
<html lang="en">
...
$ git diff HEAD
UNCOMMITTED CHANGES
diff between last commit
& current state
includes both staged and unstaged files
$ git diff HEAD^
EARLIER COMMITS
parent of latest commit
$ git diff HEAD^^ grandparent of latest commit
$ git diff HEAD~5 five commits ago
$ git diff HEAD^..HEAD second most recent commit vs. most recent
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
257256c cat
4fb063f Add index
f5a6ff9 Add catalog pages
$ git log --oneline
EARLIER COMMITS
range of abbreviated SHAs
$ git diff master bird diff between two branches
$ git diff --since=1.week.ago --until=1.minute.ago time-based diff
$ git diff f5a6sdfsfsdfsdfff9..4sdsdfsdfsdfsdffb063f range of SHAs
$ git diff 4fb063f..f5a6ff9
$ git blame index.html --date short
BLAME
commit hash author date line # content
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
...
96776a42 (Gregg 2012-06-29 9) <ul>
96776a42 (Gregg 2012-06-29 10) <li>Cats</li>
3ea7f709 (Jane 2012-06-30 11) <li>Octopi</li>
96776a42 (Gregg 2012-06-29 12) </ul>
...
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# experiments/
$ git status
EXCLUDING FILES
we don’t want to commit this...
experiments/ will exclude this folder from git
$ git status
the experiment directory is now invisible to git
.git/info/exclude
# On branch master
nothing to commit (working directory clean)
EXCLUDE PATTERNS
exclude this filetutorial.mp4
exclude all .mp4 files*.mp4
exclude directoryexperiments/
exclude .log files in logs directorylogs/*.log
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# logs/server.log don’t commit log files, they create conflicts
$ git status
EXCLUDING FROM ALL COPIES
logs/*.log
$ git status no more logs
.gitignore
add this pattern
# On branch master
nothing to commit (working directory clean)
REMOVING FILES
$ git rm README.txt
$ git status
DELETED from the local filesystem & untracked
$ git commit -m “Remove readme”
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
# Changes to be committed:
#
# deleted: README.txt
UNTRACKING FILES
$ git rm --cached development.log
$ git status
what if you’re already tracking log files?
not deleted from the local file system, only from Git
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
# Changes to be committed:
#
# deleted: development.log
UNTRACKING FILES
logs/*.log
.gitignore
$ git add .gitignore
will ignore all .log files inside the logs directory
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
$ git commit -m "Ignore all log files."
[master bccdc8c] Ignore all log files.
2 files changed, 1 insertion(+), 1 deletion(-)
create mode 100644 .gitignore
delete mode 100644 development.log
$ git config --global user.name "Gregg Pollack"
CONFIG
remember these? there’s more
use emacs for interactive commands$ git config --global core.editor emacs
use opendiff for merging conflicts$ git config --global merge.tool opendiff
OS X only
L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
$ git config --global user.email "gregg@codeschool.com"
$ git config user.email
LOCAL CONFIG
$ git config user.email "spamme@example.com"
$ git config --list
same key can
be set twice
the global config loaded first, then repo config
sets email for current repo
user.name=Gregg
user.email=gregg@codeschool.com
color.ui=true
core.editor=mate -w
user.email=spamme@example.com
spamme@example.com
ALIASES
$ git config --global alias.mylog 
"log --pretty=format:'%h %s [%an]' --graph"
$ git config --global alias.lol 
"log --graph --decorate --pretty=oneline --abbrev-commit --all"
aliases for log formats
$ git mylog
* 19f735c Merge branch 'admin' [Jane]
|
| * 7980856 Add user admin [Jane]
* | 5c9ed90 Add dashboard. [Jane]
|/
* ab48a3f Create quantum cat. [Jane]
ALIASES git config alias.<name> <command>
git st$ git config --global alias.st status
$ git st
git co$ git config --global alias.co checkout
git br$ git config --global alias.br branch
git ci$ git config --global alias.ci commit
git status
git checkout
git branch
git commit
# On branch master
nothing to commit (working directory clean)
Git_real_slides

Weitere ähnliche Inhalte

Was ist angesagt?

The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of GitDivineOmega
 
Git for beginner
Git for beginnerGit for beginner
Git for beginnerTrung Huynh
 
Using Git as your VCS with Bioconductor
Using Git as your VCS with BioconductorUsing Git as your VCS with Bioconductor
Using Git as your VCS with Bioconductortimyates
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advancedYodalee
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With GitHoffman Lab
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messesKatie Sylor-Miller
 
Version control system
Version control systemVersion control system
Version control systemAndrew Liu
 
Get going with_git_ppt
Get going with_git_pptGet going with_git_ppt
Get going with_git_pptMiraz Al-Mamun
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails UndergroundAriejan de Vroom
 
Git-ing out of your git messes - Fluent Conf 2017
Git-ing out of  your git messes - Fluent Conf 2017Git-ing out of  your git messes - Fluent Conf 2017
Git-ing out of your git messes - Fluent Conf 2017Katie Sylor-Miller
 
Git Introduction
Git IntroductionGit Introduction
Git IntroductionGareth Hall
 

Was ist angesagt? (20)

The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
DrupalCafe5 VCS
DrupalCafe5 VCSDrupalCafe5 VCS
DrupalCafe5 VCS
 
Git for beginner
Git for beginnerGit for beginner
Git for beginner
 
Git presentation
Git presentationGit presentation
Git presentation
 
Git basic
Git basicGit basic
Git basic
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Using Git as your VCS with Bioconductor
Using Git as your VCS with BioconductorUsing Git as your VCS with Bioconductor
Using Git as your VCS with Bioconductor
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With Git
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Presentacion git
Presentacion gitPresentacion git
Presentacion git
 
簡單介紹git
簡單介紹git簡單介紹git
簡單介紹git
 
Version control system
Version control systemVersion control system
Version control system
 
Basic Git
Basic GitBasic Git
Basic Git
 
Get going with_git_ppt
Get going with_git_pptGet going with_git_ppt
Get going with_git_ppt
 
GIT - GOOD PRACTICES
GIT - GOOD PRACTICESGIT - GOOD PRACTICES
GIT - GOOD PRACTICES
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
 
Git-ing out of your git messes - Fluent Conf 2017
Git-ing out of  your git messes - Fluent Conf 2017Git-ing out of  your git messes - Fluent Conf 2017
Git-ing out of your git messes - Fluent Conf 2017
 
Git Introduction
Git IntroductionGit Introduction
Git Introduction
 

Ähnlich wie Git_real_slides

Git Concepts, Commands and Connectivity
Git Concepts, Commands and ConnectivityGit Concepts, Commands and Connectivity
Git Concepts, Commands and ConnectivityRaja Soundaramourty
 
Git Basics (Professionals)
 Git Basics (Professionals) Git Basics (Professionals)
Git Basics (Professionals)bryanbibat
 
Version Control with Git for Beginners
Version Control with Git for BeginnersVersion Control with Git for Beginners
Version Control with Git for Beginnersbryanbibat
 
Git it on (includes git hub)
Git it on (includes git hub)Git it on (includes git hub)
Git it on (includes git hub)Martin Bing
 
Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615Brian K. Vagnini
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for ArtistsDavid Newbury
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitE Carter
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commandsZakaria Bouazza
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmdsrinathcox
 

Ähnlich wie Git_real_slides (20)

Git Concepts, Commands and Connectivity
Git Concepts, Commands and ConnectivityGit Concepts, Commands and Connectivity
Git Concepts, Commands and Connectivity
 
Git Basics (Professionals)
 Git Basics (Professionals) Git Basics (Professionals)
Git Basics (Professionals)
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Version Control with Git for Beginners
Version Control with Git for BeginnersVersion Control with Git for Beginners
Version Control with Git for Beginners
 
Git it on (includes git hub)
Git it on (includes git hub)Git it on (includes git hub)
Git it on (includes git hub)
 
Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615
 
Loading...git
Loading...gitLoading...git
Loading...git
 
Git
GitGit
Git
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for Artists
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Git github
Git githubGit github
Git github
 
GIT_In_90_Minutes
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutes
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Git basics
Git basicsGit basics
Git basics
 
Git and github
Git and githubGit and github
Git and github
 
Git introduction
Git introductionGit introduction
Git introduction
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Git and Github
Git and GithubGit and Github
Git and Github
 

Kürzlich hochgeladen

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 

Kürzlich hochgeladen (20)

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 

Git_real_slides

  • 1.
  • 2. GIT BASICS L E V E L 1
  • 3. L E V E L 1 — G I T B A S I C S SAME OLD STORY Collaboration Issues!
  • 5. L E V E L 1 — G I T B A S I C S REPOSITORY LOCATIONS Central Repository Distributed Repository
  • 6. DISTRIBUTED VERSION CONTROL SYSTEM Git is a (DVCS)
  • 7. L E V E L 1 — G I T B A S I C S ORIGINS • Linux Kernel project. • Meant to be distributed, fast and more natural. • Capable of handling large projects.
  • 8. L E V E L 1 — G I T B A S I C S WORKING WITH GIT • Command line interface • Official Git Site — start here http://git-scm.com/ • Many GUI tools available
  • 9. L E V E L 1 — G I T B A S I C S GIT HELP $ 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 ...
  • 10. 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 L E V E L 1 — G I T B A S I C S GIT HELP pass in any git command
  • 11. L E V E L 1 — G I T B A S I C S SETTING UP GIT 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 gregg@codeschool.com $ git config --global color.ui true
  • 12. L E V E L 1 — G I T B A S I C S STARTING A REPO git metadata is stored here $ mkdir store $ cd store $ git init Initialized empty Git repository in /Users/gregg/store/.git/
  • 13. L E V E L 1 — G I T B A S I C S GIT WORK FLOW Jane creates README.txt file Add file to staging area Commit changes Getting ready to take a picture A snapshot of those on the stage Starts as untracked
  • 14. Commit changes L E V E L 1 — G I T B A S I C S GIT WORK FLOW Jane creates README.txt file Add file to staging area Jane modifies README.txt file & adds LICENSE Add both files to staging area Commit changes
  • 15. # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README.txt nothing added to commit but untracked files present (use "git add" to track) L E V E L 1 — G I T B A S I C S Our newly created file Jane creates README.txt file $ git status To check what’s changed since last commit
  • 16. L E V E L 1 — G I T B A S I C S Our staged file $ git add README.txt git status$ # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: README.txt # Add file to staging area
  • 17. L E V E L 1 — G I T B A S I C S $ 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 master
  • 18. L E V E L 1 — G I T B A S I C S # On branch master # Changed but not updated: # # modified: README.txt # # Untracked files: # # LICENSE no changes added to commit $ git status Jane modifies README.txt file & adds LICENSE master
  • 19. L E V E L 1 — G I T B A S I C S $ git add README.txt LICENSE $ git add --all Add both files 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 master
  • 20. L E V E L 1 — G I T B A S I C S $ 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 Commit changes master
  • 21. L E V E L 1 — G I T B A S I C S GIT TIMELINE HISTORY commit 1b0019c37e3f3724fb2e9035e6bab4d7d87bf455 Author: Gregg Pollack <gregg@codeschool.com> Date: Thu Jul 5 22:31:27 2012 -0400 Add LICENSE and finish README. commit 5acaf86b04aaf9cbbb8ebb9042a20a46d0b9ce76 Author: Gregg Pollack <gregg@codeschool.com> Date: Thu Jul 5 22:00:46 2012 -0400 Create a README. $ git log master
  • 22. L E V E L 1 — G I T B A S I C S DIFFERENT WAYS TO ADD $ git add <list of files> $ git add --all $ git add *.txt Add all txt files in current directory $ git add docs/*.txt Add 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
  • 23.
  • 24.
  • 25. STAGING & REMOTES L E V E L 2
  • 26. GIT DIFF 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 $ git diff
  • 27. VIEWING STAGED DIFFERENCES $ 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 L E V E L 2 — S T A G I N G & R E M O T E S
  • 28. # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: LICENSE # HEAD UNSTAGING FILES $ git status $ Unstage Tip git reset HEAD LICENSE Refers to last commit Unstaged changes after reset: M LICENSE L E V E L 2 — S T A G I N G & R E M O T E S master
  • 29. DISCARD CHANGES $ 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 L E V E L 2 — S T A G I N G & R E M O T E S nothing to commit (working directory clean)
  • 30. HEAD SKIP STAGING AND COMMIT 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(-) L E V E L 2 — S T A G I N G & R E M O T E S master
  • 31. UNDOING A COMMIT # 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. L E V E L 2 — S T A G I N G & R E M O T E S master HEAD
  • 32. ADDING TO A COMMIT [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 file git commit --amend -m "Modify readme & add todo.txt." Whatever has been staged is added to last commit L E V E L 2 — S T A G I N G & R E M O T E S master HEAD
  • 33. USEFUL COMMANDS $ 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$ L E V E L 2 — S T A G I N G & R E M O T E S
  • 34. HOW TO SHARE? Git doesn’t take care of access control “git remote” command L E V E L 2 — S T A G I N G & R E M O T E S push pull pull Remote Repository master
  • 35. REMOTE REPOSITORY HOSTING • GitHub • BitBucket • Gitosis • Gitorious Hosted Self Managed L E V E L 2 — S T A G I N G & R E M O T E S push master
  • 36. L E V E L 2 - S T A G I N G & R E M O T E S
  • 37. L E V E L 2 - S T A G I N G & R E M O T E S
  • 38. ADDING A REMOTE 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 L E V E L 2 — S T A G I N G & R E M O T E S origin
  • 39. PUSHING TO REMOTE $ git push -u origin master remote repository name local branch to push Username for 'https://github.com': Gregg Password for 'https://Gregg@github.com': 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-gitPassword caching push master origin
  • 40. L E V E L 2 - S T A G I N G & R E M O T E S
  • 41. L E V E L 2 - S T A G I N G & R E M O T E S Same information from “git log”
  • 42. PULLING FROM REMOTE $ 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-forward todo.txt | 1 + 1 file changed, 1 insertion(+) To pull changes down from the remote L E V E L 2 — S T A G I N G & R E M O T E S pull origin It’s good to do this often
  • 43. HAVING MULTIPLE REMOTES L E V E L 2 — S T A G I N G & R E M O T E S origin production test
  • 44. WORKING WITH REMOTES $ 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 usually master L E V E L 2 — S T A G I N G & R E M O T E S
  • 45. HEROKU REMOTE $ heroku create $ git push heroku master Creating dev-server-1426... done, stack is cedar http://dev-server-1426.herokuapp.com/ | git@heroku.com: dev-server-1426.git Git remote heroku added git repo ssh address triggers deploy $ git remote -v heroku git@heroku.com: dev-server-1426.git (fetch) heroku git@heroku.com: dev-server-1426.git (push) origin https://github.com/Gregg/git-real.git (fetch) origin https://github.com/Gregg/git-real.git (push) To push to heroku L E V E L 2 — S T A G I N G & R E M O T E S
  • 46. USEFUL COMMANDS $ git reset --soft HEAD^ Don’t do these after you push git reset --hard HEAD^$ git commit --amend -m "New Message"$ git reset --hard HEAD^^$ L E V E L 2 — S T A G I N G & R E M O T E S
  • 47.
  • 48.
  • 50. COLLABORATING L E V E L 3 — C L O N I N G & B R A N C H I N G push github How do we start collaborating? JaneGregg “I want a copy” “Clone the repo!” local repo ?
  • 51. FINDING THE REPO URL URL of the remote repository L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 52. FINDING THE REPO URL URL of the remote repository L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 53. CLONING A REPOSITORY $ 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-demo Cloning into 'git-demo'... local folder name L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 54. origin https://github.com/codeschool/git-real.git (fetch) origin https://github.com/codeschool/git-real.git (push) GIT CLONE HEAD master1 - Downloads the entire repository into a new git-real directory. 2 - Adds the ‘origin’ remote, pointing it to the clone URL. 3 - Checks out initial branch (likely master). $ git remote -v sets the head L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 55. Need to work on a feature that will take some time? BRANCHING OUT master cat branch created from master Jane $ git branch cat HEAD $ git branch cat * master HEAD still on master Time to branch out. L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 56. SWITCHING TO A BRANCH HEAD Time to jump on that new 'cat' branch. HEAD is now on ‘cat’ master $ git checkout cat Switched to branch 'cat' cat Jane L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 57. master cat WORKING ON A BRANCH HEAD committed to the “cat” branch $ echo "Schrödinger" > cat.txt $ git add cat.txt $ git commit -m "Create quantum cat." [cat ab48a3f] Create quantum cat. 1 file changed, 1 insertion(+) create mode 100644 cat.txt L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 58. README.txt cat.txt master cat WORKING ON A BRANCH HEAD $ ls see the cat? L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 59. commit 1191ceb7252c9d4b1e05c9969a55766a8adfce3b Author: Gregg <gregg@codeschool.com> Date: Wed Jun 27 23:11:20 2012 -0700 Add README. master cat BACK TO MASTER $ git checkout master HEAD and we’re back on master cat.txt is gone! $ git log nothing in the log either Switched to branch 'master' $ ls README.txt L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 60. README.txt cat.txt master cat BACK TO CAT $ git checkout cat HEADphew, still here Switched to branch 'cat' $ ls L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 61. cat TIME TO MERGE Done with that feature branch? master $ git merge cat HEAD merge brings one branch’s changes into another what’s that? $ git checkout master Switched to branch 'master' $ ls README.txt Updating 1191ceb..ab48a3f Fast-forward cat.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 cat.txt Time to merge it into 'master '. no cat, as expected
  • 62. cat FAST-FORWARD TO THE FUTURE master HEAD nothing new something new Conditions for a fast-forward merge L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 63. cat BRANCH CLEAN UP When you’re done with a branch, you can safely remove it. master HEAD $ git branch -d cat Deleted branch cat (was 957dbff). L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 64. admin NON-FAST-FORWARD master Let’s work on a new admin feature. $ git checkout -b admin HEAD creates and checks out branch “Please fix the bugs on master.” Switched to a new branch 'admin' ... $ git add admin/dashboard.html $ git commit -m 'Add dashboard' ... $ git add admin/users.html $ git commit -m 'Add user admin' L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 65. admin BUG FIXING ON MASTER master$ git checkout master HEAD Switched to branch 'master' Time to put out the fire. We’ll get back to that admin branch later. $ git branch admin * master $ git pull ... $ git add store.rb $ git commit -m 'Fix store bug' ... $ git add product.rb $ git commit -m 'Fix product' ... $ git push HEAD
  • 66. admin BACK TO OUR BRANCH master $ git checkout admin HEAD $ git checkout master When ready to bring in changes Switched to branch 'admin' ... Switched to branch 'admin' $ git merge admin HEAD L E V E L 3 — C L O N I N G & B R A N C H I N G
  • 67. 1 Merge branch 'admin' 2 3 # Please enter a commit message to explain why this merge is necessary, 4 # especially if it merges an updated upstream into a topic branch. 5 # 6 # Lines starting with '#' will be ignored, and an empty message aborts 7 # the commit. AND SUDDENLY... Git uses Vi if no default editor is set to edit commit messages. + hit Enter to write (save) & quit h left l right j down k up ESC leave mode i insert mode :wq save & quit :q! cancel & quit Vi commands DON’T PANIC :wq
  • 68. Merge made by the 'recursive' strategy. 0 files changed create mode 100644 admin/dashboard.html create mode 100644 admin/users.html admin RECURSIVE MERGING master 2 commits 2 commits Git can’t fast-forward since changes were made in both branches. merge commit $ git log A commit was created to merge the two branches. commit 19f735c3556129279bb10a0d1447dc5aba1e1fa9 Merge: 5c9ed90 7980856 Author: Jane <Jane@CodeSchool.com> Date: Thu Jul 12 17:51:53 2012 -0400 Merge branch 'admin'
  • 69.
  • 70.
  • 72. push github ? I want a copy JaneGregg $ git clone https://github.com/codeschool/git-real.git Clone the repo Start making changes Jane adds two files
  • 73. TWO NEW FILES # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # product.rb # store.rb nothing added to commit but untracked files present jane $ git commit -m "Add store and product models." jane $ git status [master 30ce481] Add product and store models. 2 files changed, 2 insertions(+) create mode 100644 product.rb create mode 100644 store.rb jane $ git add --all
  • 74. COMMIT FLOW L E V E L 4 — C O L L A B O R A T I O N B A S I C S Sends her new commitjane $ git push Counting objects: 5, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (4/4), 441 bytes, done. Total 4 (delta 0), reused 0 (delta 0) To https://github.com/codeschool/git-real.git 4e67ded..30ce481 master -> master push new commits master github
  • 75. DIFFERENT GIT COMMITS L E V E L 4 — C O L L A B O R A T I O N B A S I C S same different gregg github What happens now? gregg $ git commit -am "Update the readme." [master c715339] Update the readme. 1 file changed, 1 insertion(+), 1 deletion(-)
  • 76. GIT PUSH REJECTED L E V E L 4 — C O L L A B O R A T I O N B A S I C S Cannot write over Jane’s commitgregg $ git push To https://github.com/codeschool/git-real.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/codeschool/git-real.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. $ git pull $ git push ... ... Success!
  • 77. UNDERSTANDING PULL $ git pull 1. Fetch (or Sync) our local repository with the remote one origin gregg github $ git fetch Fetch doesn’t actually update any of our local code
  • 78. UNDERSTANDING PULL $ git pull 1. Fetch (or Sync) our local repository with the remote one mastermaster origin/master gregg github 2. Merges the origin/master with master $ git merge origin/master $ git fetch
  • 79. MERGE COMMIT $ git pull 1. Fetch (or Sync) our local repository with the remote one 2. Merges the origin/master with master 1 Merge branch 'master' of https://github.com/codeschool/git-real 2 3 # Please enter a commit message to explain why this merge is necessary, 4 # especially if it merges an updated upstream into a topic branch. 5 # 6 # Lines starting with '#' will be ignored, and an empty message aborts 7 # the commit. Create a new commit for this merge my editor $ git merge origin/master
  • 80. GIT PUSH REJECTED $ git pull remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 4 (delta 0), reused 4 (delta 0) Unpacking objects: 100% (4/4), done. From https://github.com/codeschool/git-real 4e67ded..30ce481 master -> origin/master Merge made by the 'recursive' strategy. product.rb | 1 + store.rb | 1 + 2 files changed, 2 insertions(+) create mode 100644 product.rb create mode 100644 store.rb merge commit
  • 81. MERGE COMMIT $ git pull 1. Fetch (or Sync) our local repository with the remote one master origin/master 2. Merges the origin/master with master merge commit $ git fetch $ git merge origin/master
  • 82. PUSHING COMMITS $ git push Update origin/master be at the same state as our local repo master origin/master merge commit github
  • 83. OUR LOG The problem with pullgregg $ git log commit ee47baaedcd54e1957f86bda1aaa1b8a136185da Merge: 87c5243 57501d5 Author: Gregg Pollack <Gregg@CodeSchool.com> Merge branch 'master' of https://github.com/Gregg/git-real commit 87c5243d2266f05cd9fda8b1c9137f11b3fe6f31 Author: Gregg Pollack <Gregg@CodeSchool.com> Update the readme. commit 57501d595b16e2d1198a9c04c547a5b1380a6618 Author: Gregg Pollack <Gregg@CodeSchool.com> Add store and product models.
  • 84. MERGE CONFLICTS README here is my readme the cake is a lie README here is my readme the cake is telling the truth! JaneGregg same different gregg github committed committed & pushed
  • 85. MERGE CONFLICT L E V E L 4 — C O L L A B O R A T I O N B A S I C S gregg $ 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 ee47baa..4e76d35 master -> origin/master Auto-merging README.txt CONFLICT (content): Merge conflict in README.txt Automatic merge failed; fix conflicts and then commit the result. Git modified this file with the diff
  • 86. MERGE CONFLICT L E V E L 4 — C O L L A B O R A T I O N B A S I C S gregg $ git status # On branch master # Your branch and 'origin/master' have diverged, # and have 1 and 1 different commit each, respectively. # # Unmerged paths: # (use "git add/rm <file>..." as appropriate to mark resolution) # # both modified: README.txt # no changes added to commit (use "git add" and/or "git commit -a") Need to edit these files
  • 87. MERGE CONFLICT L E V E L 4 — C O L L A B O R A T I O N B A S I C S gregg $ git commit -a README here is my readme <<<<<<< HEAD the cake is a lie. ======= the cake is telling the truth! >>>>>>> 4e76d3542a7eee02ec516a47600002a90a4e4b48 here is my readme the cake is a lie.Our local version Jane’s version Edit file and correct Merge commit
  • 88. COMMIT EDITOR gregg $ git commit -a 1 Merge branch 'master' of https://github.com/Gregg/git-real 2 3 Conflicts: 4 ▸ README.txt 5 # 6 # It looks like you may be committing a merge. 7 # If this is not correct, please remove the file 8 #▸.git/MERGE_HEAD 9 # and try again. 10 11 12 # Please enter the commit message for your changes. Lines starting 13 # with '#' will be ignored, and an empty message aborts the commit. 14 # On branch master 15 # Your branch and 'origin/master' have diverged, 16 # and have 1 and 1 different commit each, respectively. EditorMerge commit
  • 89. MERGE COMMIT master origin/master Merge commit master origin/master Merge commit $ git push
  • 91.
  • 92.
  • 93. REMOTE BRANCHES & TAGS L E V E L 5
  • 94. WHY CREATE A REMOTE BRANCH? • When you need other people to work on your branch. Gregg • Any branch that will last more than a day. L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
  • 95. CREATING A REMOTE BRANCH $ git checkout -b shopping_cart Switched to a new branch 'shopping_cart' $ git push origin shopping_cart Counting objects: 10, done. Delta compression using up to 4 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (6/6), 619 bytes, done. Total 6 (delta 2), reused 0 (delta 0) To https://github.com/codeschool/git-real.git * [new branch] shopping_cart -> shopping_cart Links local branch to the remote branch (tracking) L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
  • 96. PUSHING TO THE BRANCH $ git add cart.rb $ git commit -a -m "Add basic cart ability." [shopping_cart 2a0dbf9] Add basic cart ability 1 file changed, 1 insertion(+) create mode 100644 cart.rb Pushed changes from branch$ git push Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 302 bytes, done. Total 3 (delta 1), reused 0 (delta 0) To https://github.com/codeschool/git-real.git 786d7a1..2a0dbf9 shopping_cart -> shopping_cart
  • 97.
  • 98.
  • 99. CREATING A BRANCH Hey Jane, I started a branch Sweet, I’ll check it out L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
  • 100. PULLING NEW BRANCHES remote: Counting objects: 13, done. remote: Compressing objects: 100% (6/6), done. remote: Total 9 (delta 3), reused 8 (delta 2) Unpacking objects: 100% (9/9), done. From https://github.com/Gregg/git-real 4e76d35..786d7a1 master -> origin/master * [new branch] shopping_cart -> origin/shopping_cart Updating 4e76d35..786d7a1 Fast-forward README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) remote branch $ git pull L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
  • 101. PULLING NEW BRANCHES list all remote branches Now we can contribute and push! $ git branch * master $ git branch -r origin/master origin/shopping_cart $ git checkout shopping_cart Branch shopping_cart set up to track remote branch shopping_cart from origin. Switched to a new branch 'shopping_cart' $ git branch master * shopping_cart L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
  • 102. REMOTE SHOW $ git remote show origin * remote origin Fetch URL: https://github.com/Gregg/git-real.git Push URL: https://github.com/Gregg/git-real.git HEAD branch: master Remote branches: master tracked shopping_cart tracked Local branches configured for 'git pull': master merges with remote master shopping_cart merges with remote shopping_cart Local refs configured for 'git push': master pushes to master (up to date) shopping_cart pushes to shopping_cart (local out of date)
  • 103. REMOVING A BRANCH Must delete local branch manually $ git push origin :shopping_cart To https://github.com/codeschool/git-real.git - [deleted] shopping_cart $ git branch -d shopping_cart error: The branch 'shopping_cart' is not fully merged. If you are sure you want to delete it, run 'git branch -D shopping_cart'. git branch -D shopping_cart Deleted branch shopping_cart (was ea0a1b9). $ Deletes remote branch L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
  • 104. WHAT ABOUT GREGG? L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S GreggJane
  • 105. ON DELETED REMOTE BRANCH No remote to push to (it’s just a local branch now) $ git commit -m -a "Add ability to pay." [shopping_cart 9851887] Add ability to pay. 1 file changed, 1 insertion(+), 1 deletion(-) $ git push Everything up-to-date git remote show origin$ Gregg Remote branches: master tracked refs/remotes/origin/shopping_cart stale (use 'git remote prune' to remove) git remote prune origin$ Pruning origin URL: https://github.com/codeschool/git-real.git * [pruned] origin/shopping_cart To clean up deleted remote branches
  • 106. REMOTE BRANCH NAMES $ git branch Heroku deploys only master branch Would not work, would push to staging heroku-staging * staging master $ git push heroku-staging staging $ git push heroku-staging staging:master Will push and deploy staging on heroku local:remote L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
  • 107. TAGGING v0.0.1 v0.0.2 A tag is a reference to a commit (used mostly for release versioning) Text $ git tag $ git checkout v0.0.1 list all tags check out code at commit $ git tag -a v0.0.3 -m "version 0.0.3" To add a new tag $ git push --tags To push new tags L E V E L 5 — R E M O T E B R A N C H E S A N D T A G S
  • 108.
  • 109.
  • 110. REMOTE BRANCHES & TAGS L E V E L 5
  • 111.
  • 112.
  • 113. REBASE BELONG TO US L E V E L 6
  • 114. L E V E L 6 — R E B A S E B E L O N G T O U S MERGE COMMITS ARE BAD master origin/master merge commit Add product and store models. Update the Readme. Merge branch 'master' of http... Add Cats. Merge branch 'cats' Merge commits feel useless
  • 115. DIFFERENT GIT COMMITS same different gregg github Jane’s commit gregg $ git commit -am "Update the readme." [master c715339] Update the readme. 1 file changed, 1 insertion(+), 1 deletion(-) L E V E L 6 — R E B A S E B E L O N G T O U S
  • 116. L E V E L 6 — R E B A S E B E L O N G T O U S GIT PUSH REJECTED Cannot write over Jane’s commitgregg $ git push To https://github.com/codeschool/git-real.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/codeschool/git-real.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. $ git pull $ git push ... ... Nope!
  • 117. L E V E L 6 — R E B A S E B E L O N G T O U S FETCH gregg $ git fetch remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 4 (delta 0), reused 4 (delta 0) Unpacking objects: 100% (4/4), done. From https://github.com/codeschool/git-real f35f2f1..71a4650 master -> origin/master Syncs gregg github but doesn’t merge master origin/master
  • 118. L E V E L 6 — R E B A S E B E L O N G T O U S REBASE gregg $ git rebase master origin/master 1. Move all changes to master which are not in origin/master to a temporary area. temp
  • 119. L E V E L 6 — R E B A S E B E L O N G T O U S REBASE gregg $ git rebase 1. Move all changes to master which are not in origin/master to a temporary area. 2. Run all origin/master commits. 3. Run all commits in the temporary area, one at a time. temp master origin/master
  • 120. gregg $ git rebase master 1. Move all changes to master which are not in origin/master to a temporary area. 2. Run all origin/master commits. 3. Run all commits in the temporary area, one at a time. Add product and store models. Update the Readme. No Merge Commit! REBASE
  • 121. admin LOCAL BRANCH REBASE master $ git checkout admin Switched to branch 'admin' admin master Rebase $ git rebase master ...
  • 122. IF ALL GOES WELL, MERGE MASTER $ git checkout master Switched to branch 'master' admin master $ git merge admin ...
  • 123. WHAT ABOUT CONFLICTS same gregg github Add lie to readme. Add product and store models. Add truth to readme.Add shopping cart. L E V E L 6 — R E B A S E B E L O N G T O U S Edited same file!
  • 124. L E V E L 6 — R E B A S E B E L O N G T O U S FETCH gregg $ git fetch master origin/master Add lie to readme. Add product and store models. Add truth to readme.Add shopping cart.
  • 125. gregg $ git rebase 1. Move all changes to master which are not in origin/master to a temporary area temp REBASE origin/master Add product and store models. Add truth to readme. master
  • 126. gregg $ git rebase master 2. Run all origin/master commits. Add lie to readme. Add shopping cart. 3. Run all commits in the temporary area, one at a time. REBASE temp Add product and store models. Add truth to readme.
  • 127. gregg $ git rebase First, rewinding head to replay your work on top of it... Applying: Add lie to readme. Using index info to reconstruct a base tree... M README.txt <stdin>:13: trailing whitespace. the cake is a lie, and I am your father! warning: 1 line adds whitespace errors. Falling back to patching base and 3-way merge... Auto-merging README.txt CONFLICT (content): Merge conflict in README.txt Failed to merge in the changes. Patch failed at 0001 Add lie to readme. When you have resolved this problem run "git rebase --continue". If you would prefer to skip this patch, instead run "git rebase --skip". To check out the original branch and stop rebasing run "git rebase --abort". master CONFLICT REBASE CONFLICT
  • 128. gregg $ git status # Not currently on any branch. # Unmerged paths: # (use "git reset HEAD <file>..." to unstage) # (use "git add/rm <file>..." as appropriate to mark resolution) # # both modified: README.txt # no changes added to commit (use "git add" and/or "git commit -a") Edit the README.txt gregg $ git add README.txt gregg $ git rebase --continue Applying: Add lie to readme. Applying: Add shopping cart gregg $ REBASE CONFLICT master
  • 129. REBASED LOG master Add lie to readme. Add product and store models. Add truth to readme. Add shopping cart.
  • 130. REBASE BELONG TO US L E V E L 6
  • 131.
  • 132.
  • 134. $ git log VIEWING THE LOG SHA hash commit message commit 915f242e262052b11c511dc07bef237fabb7ed85 Author: Gregg <gregg@codeschool.com> Date: Thu Jun 28 02:10:57 2012 -0700 Update index.
  • 135. COLORIZING THE LOG $ git config --global color.ui true $ git log --pretty=oneline $ git log commit 915f242e262052b11c511dc07bef237fabb7ed85 Author: Gregg <gregg@codeschool.com> Date: Thu Jun 28 02:10:57 2012 -0700 Update index 08f202691c67abd12eb886b587ac7b26d51005c7 Update index
  • 136. LOG FORMAT L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N $ git log --pretty=format:"%h %ad- %s [%an]" any string you want & placeholder data placeholder replaced with %ad author date %an author name %h SHA hash %s subject %d ref names run “git help log” for more options!
  • 137. $ git log --oneline -p PATCH 3ea7f70 I'm telling you, it's 'Octopi'. diff --git a/index.html b/index.html index 021a54e..640d66d 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ <nav> <ul> <li><a href="cat.html">Cats</a></li> - <li><a href="octopus.html">Octopuses</a></li> + <li><a href="octopi.html">Octopi</a></li> L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
  • 138. $ git log --oneline --stat STATS L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N 3ea7f70 I'm telling you, it's 'Octopi'. index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 96776a4 Add index. index.html | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
  • 139. * 30b1f8f Merge branch 'bird' into master | | * 8b8f950 Revise silly hipster name for bird aisle. * | 915f242 Add emphasis. |/ * 69728cd Update index descriptions. $ git log --oneline --graph GRAPH visual representation of the branch merging into master L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
  • 140. until DATE RANGES $ git log --until=1.minute.ago since (days)$ git log --since=1.day.ago since (hours)$ git log --since=1.hour.ago since & until (relative)$ git log --since=1.month.ago --until=2.weeks.ago since & until (absolute)$ git log --since=2000-01-01 --until=2012-12-21
  • 141. diff --git a/index.html b/index.html @@ -8,7 +8,10 @@ <nav> <ul> <li><a href="cat.html">Cats</a></li> - <li><a href="octopus.html">Octopuses</a></li> + <li><a href="birds.html">Birds</a></li> + <li><a href="hamsters.html">Hamsters</a></li> </ul> </nav> </body> $ git diff removed line DIFFS added lines L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
  • 142. diff --git a/index.html b/index.html index 021a54e..1ceb9d6 100644 @@ -8,7 +8,10 @@ <ul> <li><a href="cat.html">Cats</a></li> ... diff --git a/octopus.html b/octopus.html index 55806be..ce8a2c7 100644 @@ -2,6 +2,6 @@ <html lang="en"> ... $ git diff HEAD UNCOMMITTED CHANGES diff between last commit & current state includes both staged and unstaged files
  • 143. $ git diff HEAD^ EARLIER COMMITS parent of latest commit $ git diff HEAD^^ grandparent of latest commit $ git diff HEAD~5 five commits ago $ git diff HEAD^..HEAD second most recent commit vs. most recent L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
  • 144. 257256c cat 4fb063f Add index f5a6ff9 Add catalog pages $ git log --oneline EARLIER COMMITS range of abbreviated SHAs $ git diff master bird diff between two branches $ git diff --since=1.week.ago --until=1.minute.ago time-based diff $ git diff f5a6sdfsfsdfsdfff9..4sdsdfsdfsdfsdffb063f range of SHAs $ git diff 4fb063f..f5a6ff9
  • 145. $ git blame index.html --date short BLAME commit hash author date line # content L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N ... 96776a42 (Gregg 2012-06-29 9) <ul> 96776a42 (Gregg 2012-06-29 10) <li>Cats</li> 3ea7f709 (Jane 2012-06-30 11) <li>Octopi</li> 96776a42 (Gregg 2012-06-29 12) </ul> ...
  • 146. # Untracked files: # (use "git add <file>..." to include in what will be committed) # # experiments/ $ git status EXCLUDING FILES we don’t want to commit this... experiments/ will exclude this folder from git $ git status the experiment directory is now invisible to git .git/info/exclude # On branch master nothing to commit (working directory clean)
  • 147. EXCLUDE PATTERNS exclude this filetutorial.mp4 exclude all .mp4 files*.mp4 exclude directoryexperiments/ exclude .log files in logs directorylogs/*.log L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N
  • 148. # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # logs/server.log don’t commit log files, they create conflicts $ git status EXCLUDING FROM ALL COPIES logs/*.log $ git status no more logs .gitignore add this pattern # On branch master nothing to commit (working directory clean)
  • 149. REMOVING FILES $ git rm README.txt $ git status DELETED from the local filesystem & untracked $ git commit -m “Remove readme” L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N # Changes to be committed: # # deleted: README.txt
  • 150. UNTRACKING FILES $ git rm --cached development.log $ git status what if you’re already tracking log files? not deleted from the local file system, only from Git L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N # Changes to be committed: # # deleted: development.log
  • 151. UNTRACKING FILES logs/*.log .gitignore $ git add .gitignore will ignore all .log files inside the logs directory L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N $ git commit -m "Ignore all log files." [master bccdc8c] Ignore all log files. 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 .gitignore delete mode 100644 development.log
  • 152. $ git config --global user.name "Gregg Pollack" CONFIG remember these? there’s more use emacs for interactive commands$ git config --global core.editor emacs use opendiff for merging conflicts$ git config --global merge.tool opendiff OS X only L E V E L 7 — H I S T O R Y & C O N F I G U R A T I O N $ git config --global user.email "gregg@codeschool.com"
  • 153. $ git config user.email LOCAL CONFIG $ git config user.email "spamme@example.com" $ git config --list same key can be set twice the global config loaded first, then repo config sets email for current repo user.name=Gregg user.email=gregg@codeschool.com color.ui=true core.editor=mate -w user.email=spamme@example.com spamme@example.com
  • 154. ALIASES $ git config --global alias.mylog "log --pretty=format:'%h %s [%an]' --graph" $ git config --global alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit --all" aliases for log formats $ git mylog * 19f735c Merge branch 'admin' [Jane] | | * 7980856 Add user admin [Jane] * | 5c9ed90 Add dashboard. [Jane] |/ * ab48a3f Create quantum cat. [Jane]
  • 155. ALIASES git config alias.<name> <command> git st$ git config --global alias.st status $ git st git co$ git config --global alias.co checkout git br$ git config --global alias.br branch git ci$ git config --global alias.ci commit git status git checkout git branch git commit # On branch master nothing to commit (working directory clean)