$30 off During Our Annual Pro Sale. View Details »

Git and Github

Git and Github


May 08, 2013

More Decks by 高見龍

Other Decks in Technology


  1. Git and Github eddiekao@NCKU

  2. None
  3. Current Status 80% iOS app, 20% Ruby/Rails

  4. Before we start..

  5. You may create lots of files day by day..

  6. edit them, save, edit them, and save.. x N

  7. Backup?

  8. Ctrl-C + Ctrl-V

  9. "ProjectA" -> "ProjectA20130506" -> "ProjectA20130508-1" -> "ProjectA20130508-2" -> "ProjectA-bak" ->

  10. backup and sync on LAN

  11. Version Control

  12. Subversion (SVN)

  13. but the problem is..

  14. when network or svn server is down..

  15. Is there any better way..?

  16. Git

  17. What's Git?

  18. Version Control System (VCS)

  19. created by Linus Torvalds for managing Linux kernel source code

    in 2005
  20. distributed

  21. remote, and also local

  22. Git

  23. Git != Github

  24. Why version control?

  25. backup just like you can load saving data while playing

    RPG game
  26. history and evidence you know whom to blame when something

    is going wrong :)
  27. Why Git?

  28. free

  29. fast & smaller footprint

  30. http://git-scm.com/book/en/Getting-Started-Git-Basics some other version control system..

  31. http://git-scm.com/book/en/Getting-Started-Git-Basics git

  32. just snapshots, not differences

  33. local commit and remote push

  34. most of the operations are local

  35. easy to co-work with others

  36. But..

  37. git is easy to use, but hard to master

  38. Install Git

  39. on Mac: > brew install git on Ubuntu or some

    linux OS: > sudo apt-get install git-core or > sudo apt-get install git
  40. Exercise: please install git in your machine.

  41. How to Git

  42. configurations

  43. .gitconfig it should locate in your home directory

  44. set your username and email > git config --global user.name

    "eddie" > git config --global user.email "eddie@digik.com.tw" list all settings > git config --list
  45. make some useful aliases

  46. [alias] co = checkout br = branch aa = add

    --all l = "!source ~/.dotfiles/.githelper && pretty_git_log" https://github.com/kaochenlong/eddie-dotfiles
  47. Exercise: 1. set your username and email for git. 2.

    edit the ".gitconfig" and add some aliases.
  48. .gitignore https://github.com/github/gitignore

  49. don't be afraid of command line tools

  50. git init

  51. Exercise: please create a new directory and initialize for git

    version control.
  52. git clone

  53. git clone git://github.com/kaochenlong/eddie-vim.git

  54. Exercise: please try to copy a project from Github or

    somewhere to your local machine.
  55. working, staging, and repository

  56. http://git-scm.com/about/staging-area

  57. git add can add a single file or all modified

    files, even a single line.
  58. Exercise: add a new file named "hello.rb" and add to

    staging area.
  59. Exercise: after adding "hello.rb" to staging area, then try to

    modify it and see what happen?
  60. git status

  61. Exercise: try to check if "hello.rb" is in staging area,

    and then remove it from staging area.
  62. git mv

  63. Exercise: add "hello.rb" to staging area, and then rename it

    to "world.rb".
  64. git commit

  65. Exercise: just commit it :)

  66. When to make a Commit?!

  67. commit message matters!

  68. amend committed message

  69. git commit --amend

  70. Exercise: you just committed with a rubbish message, pleases amend

    it to make sense for your project.
  71. Exercise: in last commit, you forgot to add another file,

    but you don't want to commit again just for this single file, please try to commit it with -- amend.
  72. Notice: empty folder won't be committed!

  73. if you still want to commit an empty folder, you

    can put an empty “.gitkeep” file in it by convention.
  74. git log

  75. git log --pretty=oneline

  76. git log --pretty=format:"%h %s"

  77. git help log

  78. Exercise: check your commit log

  79. Exercise: read the help manual of “git log”, and make

    your prefer log format.
  80. Exercise: modify something in the "world.rb" then commit again.

  81. git rm

  82. Exercise: remove a file and then checkout it back.

  83. git tag

  84. tag is a milestone

  85. Exercise: create a tag for your project

  86. git branch

  87. branching is very cheap

  88. When to make a Branch?!

  89. git checkout

  90. Exercise: 1. create a new branch name "fruit" 2. checkout

    to "fruit" branch 3. add a "banana.rb" and commit it
  91. Exercise: please try to list all branches, including local and

    remote branches.
  92. Exercise: you accidentally delete the "world.rb" file, please try to

    recover it with git commands.
  93. Exercise: you just create a tag name “ncku”, try to

    checkout to this tag after several commits.
  94. git merge

  95. conflict?

  96. Exercise: 1. checkout back to "master" branch 2. merge "fruit"

    to "master" 3. remove "fruit" branch if you like
  97. git reset soft v.s. hard

  98. Exercise: reset a file to untracked status which you just

    added to staging.
  99. Exercise: you just merged a branch, please try reset it

    to back to un-merged branch.
  100. git pull

  101. git pull = git fetch + git merge

  102. git push

  103. git push origin ncku-branch

  104. git clean remove untracked files

  105. git stash apply, pop, list, clear

  106. git remote

  107. Reading References

  108. 1. Pro Git 2. ihower's blog http://ihower.tw/git/

  109. Git Flow

  110. http://git-scm.com/book/en/Git-Branching-Branching-Workflows

  111. http://nvie.com/posts/a-successful-git-branching-model/

  112. on Mac: > brew install git-flow on Ubuntu or some

    linux OS: > sudo apt-get install git-flow https://github.com/nvie/gitflow/wiki/Installation
  113. Exercise: please install git flow in your machine, and initialize

    a git flow project.
  114. init a project with git flow > git flow init

  115. Branches Master, Develop, Feature, Release, Hotfix

  116. add a new feature: > git flow feature start my_new_feature

    when done with the new feature: > git flow feature finish my_new_feature
  117. Exercise: your boss ask you to add a new feature

    which can let user upload their photos, please try to finish this assignment in git flow.
  118. Exercise: your boss find a bug and ask you to

    fix it ASAP, please try to do this assignment in git flow.
  119. Github

  120. What's Github?

  121. a git repository server

  122. coders' facebook :)

  123. None
  124. make friends with other awesome coders :)

  125. resume for coders!

  126. Free? Price?


  128. How to Github?

  129. Exercise: register a new account on Github

  130. without password?

  131. SSH Key

  132. Exercise: generate a SSH key pair in your local machine

    and add the public key to Github
  133. Exercise: create a new repository on Github

  134. git push

  135. Exercise: upload your project to Github

  136. Exercise: 1. clone a project from Github 2. do some

    changes 3. commit and push back to Github
  137. Exercise: 1. create a new local branch 2. add some

    change and then push this branch to Github
  138. tag won't be pushed to repo by default

  139. push a tag: > git push origin v2.0 push several

    tags: > git push origin --tags
  140. Exercise: create some tags for your project and upload them

    to Github
  141. git pull

  142. Fork

  143. Pull Request

  144. Exercise: 1. fork a project from your classmate who is

    sitting just next to you. 2. add some change and commit. 3. fire a pull request.
  145. Github Pages

  146. host static files for FREE

  147. upload files via git commands

  148. User pages kaochenlong.github.io

  149. Project Pages gh-pages branch

  150. custom domain name

  151. Exercise: 1. create a github page for your account. 2.

    set your domain name in CNAME if you have one.
  152. something else?

  153. bitbucket free private repo

  154. git + dropbox

  155. What's inside the .git folder?