Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Learning Git with Workflows

Mosky Liu
December 27, 2013

Learning Git with Workflows

Learn Git with workflows. It is the slides for SITCON[1] 2013 Workshop[2]: "Git - The Version Control System You Must Know".

[1]: http://sitcon.org/
[2]: http://www.openfoundry.org/tw/activities/details/415-the-open-source-way-coder

Mosky Liu

December 27, 2013
Tweet

More Decks by Mosky Liu

Other Decks in Programming

Transcript

  1. This slides won't explain every options of Git commands; and

    the internal of Git. will let you start to use Git immediately; and learn the common Git workflows. 2
  2. Mosky A Python engineer at Pinkoi An author of some

    Python packages MoSQL, Clime, ... 3
  3. Mosky A Python engineer at Pinkoi An author of some

    Python packages MoSQL, Clime, ... A speaker at several conferences PyCon APAC 2013, COSCUP 2013, PyCon TW 2013, ... 3
  4. Mosky A Python engineer at Pinkoi An author of some

    Python packages MoSQL, Clime, ... A speaker at several conferences PyCon APAC 2013, COSCUP 2013, PyCon TW 2013, ... A Python trainer 3
  5. Mosky A Python engineer at Pinkoi An author of some

    Python packages MoSQL, Clime, ... A speaker at several conferences PyCon APAC 2013, COSCUP 2013, PyCon TW 2013, ... A Python trainer http://mosky.tw/ 3
  6. Get Git! Ubuntu, Debian or any APT-based Linux $ sudo

    apt-get install git-core Mac $ brew install git http://brew.sh/ 8
  7. Get Git! Ubuntu, Debian or any APT-based Linux $ sudo

    apt-get install git-core Mac $ brew install git http://brew.sh/ Windows http://git-scm.com/download/win 8
  8. GUIs are available Thanks GitHub! "Github for Mac" http://mac.github.com/ "Github

    for Windows" http://windows.github.com/ Other http://git-scm.com/downloads/guis 10
  9. Tell Git who you are $ git config --global user.name

    "Mosky Liu" $ git config --global user.email [email protected] 11
  10. Other Git configs $ git config --global core.editor emacs $

    git config --global merge.tool vimdiff 12
  11. Other Git configs $ git config --global core.editor emacs $

    git config --global merge.tool vimdiff $ git config --list 12
  12. Other Git configs $ git config --global core.editor emacs $

    git config --global merge.tool vimdiff $ git config --list $ vim ~/.gitconfig 12
  13. Other Git configs $ git config --global core.editor emacs $

    git config --global merge.tool vimdiff $ git config --list $ vim ~/.gitconfig http://j.mp/mosky-gitconfig 12
  14. Simplest Workflow (1) $ git init <directory> (2) (modify file)

    (3) $ git add <file> ... (4) $ git commit 16
  15. Simplest Workflow (1) $ git init <directory> (2) (modify file)

    (3) $ git add <file> ... (4) $ git commit # Back 2 16
  16. Simplest Workflow (1) $ git init <directory> (2) (modify file)

    (3) $ git add <file> ... (4) $ git commit # Back 2 The end of the core --- it's super easy! 16
  17. Name commit $ git tag <tagname> $ git checkout 599d439

    $ git tag v0.1 $ git checkout v0.1 22
  18. Create a branch $ git branch <branchname> $ git checkout

    <branchname> or $ git checkout -b <branchname> 32
  19. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) 37
  20. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) ... 37
  21. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) ... (4) $ git commit 37
  22. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) ... (4) $ git commit # Back 3 until finish "topic" 37
  23. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) ... (4) $ git commit # Back 3 until finish "topic" (5) $ git checkout <base-branch> 37
  24. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) ... (4) $ git commit # Back 3 until finish "topic" (5) $ git checkout <base-branch> (6) $ git merge <topic-branch> 37
  25. Clone a remote repository $ git clone <repos> <dir> <repos>

    https:// github.com/torvalds/linux.git 39
  26. Add, remove and list remotes $ git remote add <name>

    <url> <url> can be a local path. 41
  27. Add, remove and list remotes $ git remote add <name>

    <url> <url> can be a local path. $ git remote remove <name> 41
  28. Add, remove and list remotes $ git remote add <name>

    <url> <url> can be a local path. $ git remote remove <name> $ git remote 41
  29. Push commits to remote $ git push <repos> <refspec>... <refspec>

    usually is branch or tag name [+]<src>[:<dst>] :<dst> to delete remote reference. 42
  30. Three Principles 1. master is production. 2. dev only includes

    stable and reviewed code. 3. Create topic branch to resolve issue all the time. 45
  31. Three Phases 1. Resolving Create a topic branch to resolve

    issue. 2. Reviewing Review the code. 46
  32. Three Phases 1. Resolving Create a topic branch to resolve

    issue. 2. Reviewing Review the code. 3. Cleanup Merge into dev and remove topic branch. 46
  33. 47

  34. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!"

    Assignee (dev) $ git checkout -b topic 47
  35. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!"

    Assignee (dev) $ git checkout -b topic Assignee (topic) $ (commit...) 47
  36. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!"

    Assignee (dev) $ git checkout -b topic Assignee (topic) $ (commit...) Assignee (topic) $ git push origin topic 47
  37. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!"

    Assignee (dev) $ git checkout -b topic Assignee (topic) $ (commit...) Assignee (topic) $ git push origin topic Until resolve, call assigner for review. 47
  38. 48

  39. Assignee: "I resolved!" Assigner: "Let me review." Assigner (dev) $

    git checkout -b topic Assigner (topic) $ git pull origin topic 48
  40. Assignee: "I resolved!" Assigner: "Let me review." Assigner (dev) $

    git checkout -b topic Assigner (topic) $ git pull origin topic Assigner (topic) $ git diff ...dev 48
  41. Assignee: "I resolved!" Assigner: "Let me review." Assigner (dev) $

    git checkout -b topic Assigner (topic) $ git pull origin topic Assigner (topic) $ git diff ...dev If it is not good enough, call assignee to fix. 48
  42. 49

  43. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic Assigner (dev) $ git push origin dev 49
  44. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic Assigner (dev) $ git push origin dev Assigner: "Good job!" 49
  45. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic Assigner (dev) $ git push origin dev Assigner: "Good job!" Assignee (dev) $ git branch -d topic 49
  46. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic Assigner (dev) $ git push origin dev Assigner: "Good job!" Assignee (dev) $ git branch -d topic Assignee (dev) $ git push origin :topic 49
  47. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic Assigner (dev) $ git push origin dev Assigner: "Good job!" Assignee (dev) $ git branch -d topic Assignee (dev) $ git push origin :topic Assignee (dev) $ git pull origin dev 49
  48. End

  49. End Use branch! Workflow does matter. Git still has many

    magics. Tips: http://j.mp/mosky-gitconfig 52
  50. End Use branch! Workflow does matter. Git still has many

    magics. Tips: http://j.mp/mosky-gitconfig Q&A 52