SlideShare ist ein Scribd-Unternehmen logo
1 von 51
Git
Victor Wong
Outline
Install and Configure Git (x)

Git Concepts

Git Commands

Git Workflow

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 config --global user.name "Victor Wong"

 $ git config --global user.email
 "victorwkm@gmail.com"

 $ git config user.name

 bonus: $ cat ~/.gitconfig
Add color to status and
        branch


 $ git config --global color.status auto

 $ git config --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 <file>..." to unstage)



# Changed but not updated:

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

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



# Untracked files:

#   (use "git add <file>..." to include in what will be committed)
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-reflog

 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 files changed, 1 insertions(+), 0 deletions(-)
Conflict
$   git status
$   vim index.html
$   git add index.html
$   git commit
.git/



config

hooks (pre-commit, post-commit, ...)
Git Workflow
Distributed Workflows
Centralized Workflow
         (us)
Integration-Manager
 Workflow (GitHub)
Dictator and Lieutenants
    Workflow (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 files in a project? Some files
such as .log which shouldn't be include in every
   project, can I ignore it in every projects?
How do I ignore files in a project? Some files
such as .log which shouldn't be include in every
   project, can I ignore it in every projects?

    $ vim .gitignore

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



    $ vim ~/.gitignore_global

    $ git config --global core.excludesfile ~/.gitignore_global

    Bonus: git config --global --list

    Remind: Don't add too much files in the globa excludesfile
Search commit message
Search commit message
 git log -g --grep=<pattern>



 -g, --walk-reflogs

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

 --grep=<pattern>

 Limit the commits output to ones with log message that
 matches the specified pattern (regular expression).
Can I change the filename case in Git?
       fatal: destination exists,
  source=font.ttf, destination=Font.ttf
Can I change the filename 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-config.php in the server
- remove it on the GitHub, so your colleagues won't get a copy of
the wp-config.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-config.php in the server
- remove it on the GitHub, so your colleagues won't get a copy of
the wp-config.php


     [On the server]

     $ vim .gitignore

     $ git commit -am 'ignore wp-config.php file'

     $ git rm --cached wp-config.php

     $ git commit -m 'remove wp-config.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 fixed
now! Hence, you tried to switch your branch to "hotfix" or
"master" to do a quick fix, 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 fixed
now! Hence, you tried to switch your branch to "hotfix" or
"master" to do a quick fix, but your working dirctory is
"dirty", what should you do?

     $ git stash

     $ git checkout master

     ... fix issue ...

     $ git commit -am "fix 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 finishing 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

Weitere ähnliche Inhalte

Was ist angesagt?

Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git HubOpen Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git Hub
Nick Quaranto
 

Was ist angesagt? (20)

Git advanced
Git advancedGit advanced
Git advanced
 
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
 
沒有 GUI 的 Git
沒有 GUI 的 Git沒有 GUI 的 Git
沒有 GUI 的 Git
 
Git Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierGit Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easier
 
Git
GitGit
Git
 
Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git HubOpen Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git Hub
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 Workshop
 
How to become a Git power user
How to become a Git power userHow to become a Git power user
How to become a Git power user
 
Undoing Things in Git
Undoing Things in GitUndoing Things in Git
Undoing Things in Git
 
Git Basics - RubyFest 2009
Git Basics - RubyFest 2009Git Basics - RubyFest 2009
Git Basics - RubyFest 2009
 
My Notes from https://www.codeschool.com/courses/git-real
My Notes from  https://www.codeschool.com/courses/git-realMy Notes from  https://www.codeschool.com/courses/git-real
My Notes from https://www.codeschool.com/courses/git-real
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a BossGit Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
 
Git SCM
Git SCMGit SCM
Git SCM
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Enjoy privacy on Gitlab
Enjoy privacy on GitlabEnjoy privacy on Gitlab
Enjoy privacy on Gitlab
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git workshop
Git workshopGit workshop
Git workshop
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 

Ähnlich wie Git Distributed Version Control System

Ähnlich wie Git Distributed Version Control System (20)

Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
.Git for WordPress Developers
.Git for WordPress Developers.Git for WordPress Developers
.Git for WordPress Developers
 
Git101
Git101Git101
Git101
 
Git basics
Git basicsGit basics
Git basics
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for Artists
 
Git github
Git githubGit github
Git github
 
Becoming a Git Master
Becoming a Git MasterBecoming a Git Master
Becoming a Git Master
 
Loading...git
Loading...gitLoading...git
Loading...git
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
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
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 
Jedi Mind Tricks for Git
Jedi Mind Tricks for GitJedi Mind Tricks for Git
Jedi Mind Tricks for Git
 
Improving your workflow with git
Improving your workflow with gitImproving your workflow with git
Improving your workflow with git
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Github By Nyros Developer
Github By Nyros DeveloperGithub By Nyros Developer
Github By Nyros Developer
 
Jedi Mind Tricks in Git
Jedi Mind Tricks in GitJedi Mind Tricks in Git
Jedi Mind Tricks in Git
 
Working in Team using Git in Unity
Working in Team using Git in UnityWorking in Team using Git in Unity
Working in Team using Git in Unity
 

Git Distributed Version Control System

  • 2. Outline Install and Configure Git (x) Git Concepts Git Commands Git Workflow 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 config --global user.name "Victor Wong" $ git config --global user.email "victorwkm@gmail.com" $ git config user.name bonus: $ cat ~/.gitconfig
  • 5. Add color to status and branch $ git config --global color.status auto $ git config --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 <file>..." to unstage) # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # Untracked files: # (use "git add <file>..." to include in what will be committed)
  • 8.
  • 9.
  • 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-reflog 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 files changed, 1 insertions(+), 0 deletions(-)
  • 21. $ git status $ vim index.html $ git add index.html $ git commit
  • 24.
  • 28. Dictator and Lieutenants Workflow (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 files in a project? Some files such as .log which shouldn't be include in every project, can I ignore it in every projects?
  • 35. How do I ignore files in a project? Some files such as .log which shouldn't be include in every project, can I ignore it in every projects? $ vim .gitignore ... add the file and folder path that you don't want git to track ... $ vim ~/.gitignore_global $ git config --global core.excludesfile ~/.gitignore_global Bonus: git config --global --list Remind: Don't add too much files in the globa excludesfile
  • 37. Search commit message git log -g --grep=<pattern> -g, --walk-reflogs Instead of walking the commit ancestry chain, walk reflog entries from the most recent one to older ones. --grep=<pattern> Limit the commits output to ones with log message that matches the specified pattern (regular expression).
  • 38. Can I change the filename case in Git? fatal: destination exists, source=font.ttf, destination=Font.ttf
  • 39. Can I change the filename 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-config.php in the server - remove it on the GitHub, so your colleagues won't get a copy of the wp-config.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-config.php in the server - remove it on the GitHub, so your colleagues won't get a copy of the wp-config.php [On the server] $ vim .gitignore $ git commit -am 'ignore wp-config.php file' $ git rm --cached wp-config.php $ git commit -m 'remove wp-config.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 fixed now! Hence, you tried to switch your branch to "hotfix" or "master" to do a quick fix, 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 fixed now! Hence, you tried to switch your branch to "hotfix" or "master" to do a quick fix, but your working dirctory is "dirty", what should you do? $ git stash $ git checkout master ... fix issue ... $ git commit -am "fix 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 finishing 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

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n