ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Git
Victor Wong
Outline
Install and Con?gure Git (x)

Git Concepts

Git Commands

Git Work?ow

Git Hosting (GitHub, Bitbucket)

Case Studies
Installation

Git for OS X

http://code.google.com/p/git-osx-installer/



Git for Windows

http://code.google.com/p/msysgit/
Setting user's name and
  email globally in git

 $ git con?g --global user.name "Victor Wong"

 $ git con?g --global user.email
 "victorwkm@gmail.com"

 $ git con?g user.name

 bonus: $ cat ~/.gitcon?g
Add color to status and
        branch


 $ git con?g --global color.status auto

 $ git con?g --global color.branch auto
Git Concepts
Git Concepts
remote repo <-> local repo <-> staging area <-> working directory


# On branch master

# Changes to be committed:

#   (use "git reset HEAD <?le>..." to unstage)



# Changed but not updated:

#   (use "git add <?le>..." to update what will be committed)

#   (use "git checkout -- <?le>..." to discard changes in working directory)



# Untracked ?les:

#   (use "git add <?le>..." to include in what will be committed)
Git   Distributed Version Control System
Git   Distributed Version Control System
Basic Git Commands
Creating & Getting   Branching        Inspection
  init                 branch           log
  clone                checkout         show
                       merge

Basic                Remote Sharing
  status               remote
  add                  push
  commit               pull
  mv, rm               fetch
  tag
Advanced Git Commands
 git-stash git-pop git-apply

 git-blame git-diff git-re?og

 git-reset git-revert

 git-clean

 git-rebase

 git-fetch
Branch
$ git branch testing
$ git checkout testing
new commit on testing branch
$ git checkout master
$ git commit -m 'Change the master!'
Merge
$ git checkout master
$ git merge iss53
Merge made by recursive.
README | 1 +
1 ?les changed, 1 insertions(+), 0 deletions(-)
Con?ict
$   git status
$   vim index.html
$   git add index.html
$   git commit
.git/



con?g

hooks (pre-commit, post-commit, ...)
Git Work?ow
Git   Distributed Version Control System
Distributed Work?ows
Centralized Work?ow
         (us)
Integration-Manager
 Work?ow (GitHub)
Dictator and Lieutenants
    Work?ow (Linux)
github.com
GitHub

Code Review

Commit Comments

Analyze Branches

Compare View

Pull request
Case Studies
Can I change the commit
message before or after push?
Can I change the commit
message before or after push?


  $ git commit --amend

  bonus: $ git rebase -i

  Note: Never change your commit history
  after push to a public repository!
How do I ignore ?les in a project? Some ?les
such as .log which shouldn't be include in every
   project, can I ignore it in every projects?
How do I ignore ?les in a project? Some ?les
such as .log which shouldn't be include in every
   project, can I ignore it in every projects?

    $ vim .gitignore

    ... add the ?le and folder path that you don't want git to
    track ...



    $ vim ~/.gitignore_global

    $ git con?g --global core.excludes?le ~/.gitignore_global

    Bonus: git con?g --global --list

    Remind: Don't add too much ?les in the globa excludes?le
Search commit message
Search commit message
 git log -g --grep=<pattern>



 -g, --walk-re?ogs

 Instead of walking the commit ancestry chain, walk
 re?og entries from the most recent one to older ones.

 --grep=<pattern>

 Limit the commits output to ones with log message that
 matches the speci?ed pattern (regular expression).
Can I change the ?lename case in Git?
       fatal: destination exists,
  source=font.ttf, destination=Font.ttf
Can I change the ?lename case in Git?
       fatal: destination exists,
  source=font.ttf, destination=Font.ttf




   git mv -f font.ttf Font.ttf
You have pushed a WordPress folder in the Github and pull it from
the server.
But you make a mistake, you want to
- keep the wp-con?g.php in the server
- remove it on the GitHub, so your colleagues won't get a copy of
the wp-con?g.php
You have pushed a WordPress folder in the Github and pull it from
the server.
But you make a mistake, you want to
- keep the wp-con?g.php in the server
- remove it on the GitHub, so your colleagues won't get a copy of
the wp-con?g.php


     [On the server]

     $ vim .gitignore

     $ git commit -am 'ignore wp-con?g.php ?le'

     $ git rm --cached wp-con?g.php

     $ git commit -m 'remove wp-con?g.php'

     $ git push
Clients: This feature worked well in the past.
Why does it not work properly today?
We: How do we use Git to quickly identify the
issue?
Clients: This feature worked well in the past.
Why does it not work properly today?
We: How do we use Git to quickly identify the
issue?


    Use GitHub to:

      search

      history

      blame

    $ git checkout <commit-sha>
Can I undo a git
    commit?
Can I undo a git
         commit?
Preserve all changes as unstaged changes

$ git reset HEAD^



Preserve all changes

$ git reset --soft HEAD^



Discard all changes

$ git reset --hard HEAD^
You are on a branch called "development", and you received
an email from the client said this bug needs to be ?xed
now! Hence, you tried to switch your branch to "hot?x" or
"master" to do a quick ?x, but your working dirctory is
"dirty", what should you do?
You are on a branch called "development", and you received
an email from the client said this bug needs to be ?xed
now! Hence, you tried to switch your branch to "hot?x" or
"master" to do a quick ?x, but your working dirctory is
"dirty", what should you do?

     $ git stash

     $ git checkout master

     ... ?x issue ...

     $ git commit -am "?x issue #100"

     $ git checkout development

     $ git stash list

     $ git stash pop

     bonus: $ git stash apply stash@{0} $ git stash drop stash@{0}
The same code can also applied to the
following scenario.

After ?nishing the development, you suddenly
realized the you are developing a feature on
the WRONG branch. Can I save those
changes and apply those changes in the
correct branch?
Recommendations

Read the git ERROR message

Commit or lose it

Do one thing at a time (the smaller the
better)

Don¡¯t modify any history after pushing to live

Practice together
References



Git Reference http://gitref.org/

Pro Git http://git-scm.com/book
Git   Distributed Version Control System
Ad

Recommended

Gittalk
Gittalk
prtinsley
?
Recovering From Git Mistakes - Nina Zakharenko
Recovering From Git Mistakes - Nina Zakharenko
Nina Zakharenko
?
Introduction To Git Workshop
Introduction To Git Workshop
themystic_ca
?
git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)
Carlos Duarte do Nascimento
?
Advanced Git
Advanced Git
Sergiu-Ioan Ungur
?
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Codemotion
?
Git - Get Ready To Use It
Git - Get Ready To Use It
Daniel Kummer
?
Git and git workflow best practice
Git and git workflow best practice
Majid Hosseini
?
Git advanced
Git advanced
Peter Vandenabeele
?
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Codemotion
?
›]ÓÐ GUI µÄ Git
›]ÓÐ GUI µÄ Git
Chia Wei Tsai
?
Git Tricks ¡ª git utilities that make life git easier
Git Tricks ¡ª git utilities that make life git easier
Christoph Matthies
?
Git
Git
Shinu Suresh
?
Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git Hub
Nick Quaranto
?
Git 101 Workshop
Git 101 Workshop
Joy Seng
?
How to become a Git power user
How to become a Git power user
Deveo
?
Undoing Things in Git
Undoing Things in Git
gittower
?
Git Basics - RubyFest 2009
Git Basics - RubyFest 2009
Ariejan de Vroom
?
My Notes from https://www.codeschool.com/courses/git-real
My Notes from https://www.codeschool.com/courses/git-real
Eneldo Serrata
?
Learn Git Basics
Learn Git Basics
Prakash Dantuluri
?
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
tmacwilliam
?
Git SCM
Git SCM
Stefan Prutianu
?
Git real slides
Git real slides
Lucas Couto
?
Enjoy privacy on Gitlab
Enjoy privacy on Gitlab
Maxis Kao
?
Git: basic to advanced
Git: basic to advanced
Yodalee
?
Introduction to Git
Introduction to Git
Rick Umali
?
Git workshop
Git workshop
Ray Toal
?
Git and git flow
Git and git flow
Fran Garc¨ªa
?
Git Memento of basic commands
Git Memento of basic commands
Zakaria Bouazza
?
Git walkthrough
Git walkthrough
Bimal Jain
?

More Related Content

What's hot (20)

Git advanced
Git advanced
Peter Vandenabeele
?
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Codemotion
?
›]ÓÐ GUI µÄ Git
›]ÓÐ GUI µÄ Git
Chia Wei Tsai
?
Git Tricks ¡ª git utilities that make life git easier
Git Tricks ¡ª git utilities that make life git easier
Christoph Matthies
?
Git
Git
Shinu Suresh
?
Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git Hub
Nick Quaranto
?
Git 101 Workshop
Git 101 Workshop
Joy Seng
?
How to become a Git power user
How to become a Git power user
Deveo
?
Undoing Things in Git
Undoing Things in Git
gittower
?
Git Basics - RubyFest 2009
Git Basics - RubyFest 2009
Ariejan de Vroom
?
My Notes from https://www.codeschool.com/courses/git-real
My Notes from https://www.codeschool.com/courses/git-real
Eneldo Serrata
?
Learn Git Basics
Learn Git Basics
Prakash Dantuluri
?
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
tmacwilliam
?
Git SCM
Git SCM
Stefan Prutianu
?
Git real slides
Git real slides
Lucas Couto
?
Enjoy privacy on Gitlab
Enjoy privacy on Gitlab
Maxis Kao
?
Git: basic to advanced
Git: basic to advanced
Yodalee
?
Introduction to Git
Introduction to Git
Rick Umali
?
Git workshop
Git workshop
Ray Toal
?
Git and git flow
Git and git flow
Fran Garc¨ªa
?
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Codemotion
?
Git Tricks ¡ª git utilities that make life git easier
Git Tricks ¡ª git utilities that make life git easier
Christoph Matthies
?
Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git Hub
Nick Quaranto
?
Git 101 Workshop
Git 101 Workshop
Joy Seng
?
How to become a Git power user
How to become a Git power user
Deveo
?
Undoing Things in Git
Undoing Things in Git
gittower
?
My Notes from https://www.codeschool.com/courses/git-real
My Notes from https://www.codeschool.com/courses/git-real
Eneldo Serrata
?
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
tmacwilliam
?
Enjoy privacy on Gitlab
Enjoy privacy on Gitlab
Maxis Kao
?
Git: basic to advanced
Git: basic to advanced
Yodalee
?
Introduction to Git
Introduction to Git
Rick Umali
?

Similar to Git Distributed Version Control System (20)

Git Memento of basic commands
Git Memento of basic commands
Zakaria Bouazza
?
Git walkthrough
Git walkthrough
Bimal Jain
?
github ppt git ppt on git hub to know ab
github ppt git ppt on git hub to know ab
infoinnext
?
sample.pptx
sample.pptx
UshaSuray
?
GIT.pptx
GIT.pptx
Soumen Debgupta
?
Git session Dropsolid.com
Git session Dropsolid.com
dropsolid
?
Git and github 101
Git and github 101
Senthilkumar Gopal
?
Advanced Git Tutorial
Advanced Git Tutorial
Sage Sharp
?
git.ppt.pdf
git.ppt.pdf
Roniel Lopez Alvarez
?
Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHub
Kim Moir
?
390a gitintro 12au
390a gitintro 12au
Nguyen Van Hung
?
Introduction to Git and GitHub
Introduction to Git and GitHub
Bioinformatics and Computational Biosciences Branch
?
An introduction to Git
An introduction to Git
Muhil Vannan
?
Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git
John Tighe
?
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
DSC GVP
?
Git presentation
Git presentation
Vikas Yaligar
?
Git training v10
Git training v10
Skander Hamza
?
git.ppt.pptx power point presentation got Google internet
git.ppt.pptx power point presentation got Google internet
rani marri
?
Fundamentals and basics of Git and commands
Fundamentals and basics of Git and commands
DivyanshGupta922023
?
Github git-cheat-sheet
Github git-cheat-sheet
jaehyok Song
?
Git Memento of basic commands
Git Memento of basic commands
Zakaria Bouazza
?
github ppt git ppt on git hub to know ab
github ppt git ppt on git hub to know ab
infoinnext
?
Git session Dropsolid.com
Git session Dropsolid.com
dropsolid
?
Advanced Git Tutorial
Advanced Git Tutorial
Sage Sharp
?
Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHub
Kim Moir
?
An introduction to Git
An introduction to Git
Muhil Vannan
?
Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git
John Tighe
?
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
DSC GVP
?
git.ppt.pptx power point presentation got Google internet
git.ppt.pptx power point presentation got Google internet
rani marri
?
Fundamentals and basics of Git and commands
Fundamentals and basics of Git and commands
DivyanshGupta922023
?
Github git-cheat-sheet
Github git-cheat-sheet
jaehyok Song
?
Ad

Git Distributed Version Control System

  • 2. Outline Install and Con?gure Git (x) Git Concepts Git Commands Git Work?ow Git Hosting (GitHub, Bitbucket) Case Studies
  • 3. Installation Git for OS X http://code.google.com/p/git-osx-installer/ Git for Windows http://code.google.com/p/msysgit/
  • 4. Setting user's name and email globally in git $ git con?g --global user.name "Victor Wong" $ git con?g --global user.email "victorwkm@gmail.com" $ git con?g user.name bonus: $ cat ~/.gitcon?g
  • 5. Add color to status and branch $ git con?g --global color.status auto $ git con?g --global color.branch auto
  • 7. Git Concepts remote repo <-> local repo <-> staging area <-> working directory # On branch master # Changes to be committed: # (use "git reset HEAD <?le>..." to unstage) # Changed but not updated: # (use "git add <?le>..." to update what will be committed) # (use "git checkout -- <?le>..." to discard changes in working directory) # Untracked ?les: # (use "git add <?le>..." to include in what will be committed)
  • 10. Basic Git Commands Creating & Getting Branching Inspection init branch log clone checkout show merge Basic Remote Sharing status remote add push commit pull mv, rm fetch tag
  • 11. Advanced Git Commands git-stash git-pop git-apply git-blame git-diff git-re?og git-reset git-revert git-clean git-rebase git-fetch
  • 13. $ git branch testing
  • 14. $ git checkout testing
  • 15. new commit on testing branch
  • 16. $ git checkout master
  • 17. $ git commit -m 'Change the master!'
  • 18. Merge
  • 19. $ git checkout master $ git merge iss53 Merge made by recursive. README | 1 + 1 ?les changed, 1 insertions(+), 0 deletions(-)
  • 21. $ git status $ vim index.html $ git add index.html $ git commit
  • 28. Dictator and Lieutenants Work?ow (Linux)
  • 30. GitHub Code Review Commit Comments Analyze Branches Compare View Pull request
  • 32. Can I change the commit message before or after push?
  • 33. Can I change the commit message before or after push? $ git commit --amend bonus: $ git rebase -i Note: Never change your commit history after push to a public repository!
  • 34. How do I ignore ?les in a project? Some ?les such as .log which shouldn't be include in every project, can I ignore it in every projects?
  • 35. How do I ignore ?les in a project? Some ?les such as .log which shouldn't be include in every project, can I ignore it in every projects? $ vim .gitignore ... add the ?le and folder path that you don't want git to track ... $ vim ~/.gitignore_global $ git con?g --global core.excludes?le ~/.gitignore_global Bonus: git con?g --global --list Remind: Don't add too much ?les in the globa excludes?le
  • 37. Search commit message git log -g --grep=<pattern> -g, --walk-re?ogs Instead of walking the commit ancestry chain, walk re?og entries from the most recent one to older ones. --grep=<pattern> Limit the commits output to ones with log message that matches the speci?ed pattern (regular expression).
  • 38. Can I change the ?lename case in Git? fatal: destination exists, source=font.ttf, destination=Font.ttf
  • 39. Can I change the ?lename case in Git? fatal: destination exists, source=font.ttf, destination=Font.ttf git mv -f font.ttf Font.ttf
  • 40. You have pushed a WordPress folder in the Github and pull it from the server. But you make a mistake, you want to - keep the wp-con?g.php in the server - remove it on the GitHub, so your colleagues won't get a copy of the wp-con?g.php
  • 41. You have pushed a WordPress folder in the Github and pull it from the server. But you make a mistake, you want to - keep the wp-con?g.php in the server - remove it on the GitHub, so your colleagues won't get a copy of the wp-con?g.php [On the server] $ vim .gitignore $ git commit -am 'ignore wp-con?g.php ?le' $ git rm --cached wp-con?g.php $ git commit -m 'remove wp-con?g.php' $ git push
  • 42. Clients: This feature worked well in the past. Why does it not work properly today? We: How do we use Git to quickly identify the issue?
  • 43. Clients: This feature worked well in the past. Why does it not work properly today? We: How do we use Git to quickly identify the issue? Use GitHub to: search history blame $ git checkout <commit-sha>
  • 44. Can I undo a git commit?
  • 45. Can I undo a git commit? Preserve all changes as unstaged changes $ git reset HEAD^ Preserve all changes $ git reset --soft HEAD^ Discard all changes $ git reset --hard HEAD^
  • 46. You are on a branch called "development", and you received an email from the client said this bug needs to be ?xed now! Hence, you tried to switch your branch to "hot?x" or "master" to do a quick ?x, but your working dirctory is "dirty", what should you do?
  • 47. You are on a branch called "development", and you received an email from the client said this bug needs to be ?xed now! Hence, you tried to switch your branch to "hot?x" or "master" to do a quick ?x, but your working dirctory is "dirty", what should you do? $ git stash $ git checkout master ... ?x issue ... $ git commit -am "?x issue #100" $ git checkout development $ git stash list $ git stash pop bonus: $ git stash apply stash@{0} $ git stash drop stash@{0}
  • 48. The same code can also applied to the following scenario. After ?nishing the development, you suddenly realized the you are developing a feature on the WRONG branch. Can I save those changes and apply those changes in the correct branch?
  • 49. Recommendations Read the git ERROR message Commit or lose it Do one thing at a time (the smaller the better) Don¡¯t modify any history after pushing to live Practice together
  • 50. References Git Reference http://gitref.org/ Pro Git http://git-scm.com/book

Editor's Notes