Slide 1

Slide 1 text

Git and Github eddiekao@NCKU

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Current Status 80% iOS app, 20% Ruby/Rails

Slide 4

Slide 4 text

Before we start..

Slide 5

Slide 5 text

You may create lots of files day by day..

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Backup?

Slide 8

Slide 8 text

Ctrl-C + Ctrl-V

Slide 9

Slide 9 text

"ProjectA" -> "ProjectA20130506" -> "ProjectA20130508-1" -> "ProjectA20130508-2" -> "ProjectA-bak" -> "ProjectA-forEddie"

Slide 10

Slide 10 text

backup and sync on LAN

Slide 11

Slide 11 text

Version Control

Slide 12

Slide 12 text

Subversion (SVN)

Slide 13

Slide 13 text

but the problem is..

Slide 14

Slide 14 text

when network or svn server is down..

Slide 15

Slide 15 text

Is there any better way..?

Slide 16

Slide 16 text

Git

Slide 17

Slide 17 text

What's Git?

Slide 18

Slide 18 text

Version Control System (VCS)

Slide 19

Slide 19 text

created by Linus Torvalds for managing Linux kernel source code in 2005

Slide 20

Slide 20 text

distributed

Slide 21

Slide 21 text

remote, and also local

Slide 22

Slide 22 text

Git

Slide 23

Slide 23 text

Git != Github

Slide 24

Slide 24 text

Why version control?

Slide 25

Slide 25 text

backup just like you can load saving data while playing RPG game

Slide 26

Slide 26 text

history and evidence you know whom to blame when something is going wrong :)

Slide 27

Slide 27 text

Why Git?

Slide 28

Slide 28 text

free

Slide 29

Slide 29 text

fast & smaller footprint

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

just snapshots, not differences

Slide 33

Slide 33 text

local commit and remote push

Slide 34

Slide 34 text

most of the operations are local

Slide 35

Slide 35 text

easy to co-work with others

Slide 36

Slide 36 text

But..

Slide 37

Slide 37 text

git is easy to use, but hard to master

Slide 38

Slide 38 text

Install Git

Slide 39

Slide 39 text

on Mac: > brew install git on Ubuntu or some linux OS: > sudo apt-get install git-core or > sudo apt-get install git

Slide 40

Slide 40 text

Exercise: please install git in your machine.

Slide 41

Slide 41 text

How to Git

Slide 42

Slide 42 text

configurations

Slide 43

Slide 43 text

.gitconfig it should locate in your home directory

Slide 44

Slide 44 text

set your username and email > git config --global user.name "eddie" > git config --global user.email "[email protected]" list all settings > git config --list

Slide 45

Slide 45 text

make some useful aliases

Slide 46

Slide 46 text

[alias] co = checkout br = branch aa = add --all l = "!source ~/.dotfiles/.githelper && pretty_git_log" https://github.com/kaochenlong/eddie-dotfiles

Slide 47

Slide 47 text

Exercise: 1. set your username and email for git. 2. edit the ".gitconfig" and add some aliases.

Slide 48

Slide 48 text

.gitignore https://github.com/github/gitignore

Slide 49

Slide 49 text

don't be afraid of command line tools

Slide 50

Slide 50 text

git init

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

git clone

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

Exercise: please try to copy a project from Github or somewhere to your local machine.

Slide 55

Slide 55 text

working, staging, and repository

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

git add can add a single file or all modified files, even a single line.

Slide 58

Slide 58 text

Exercise: add a new file named "hello.rb" and add to staging area.

Slide 59

Slide 59 text

Exercise: after adding "hello.rb" to staging area, then try to modify it and see what happen?

Slide 60

Slide 60 text

git status

Slide 61

Slide 61 text

Exercise: try to check if "hello.rb" is in staging area, and then remove it from staging area.

Slide 62

Slide 62 text

git mv

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

git commit

Slide 65

Slide 65 text

Exercise: just commit it :)

Slide 66

Slide 66 text

When to make a Commit?!

Slide 67

Slide 67 text

commit message matters!

Slide 68

Slide 68 text

amend committed message

Slide 69

Slide 69 text

git commit --amend

Slide 70

Slide 70 text

Exercise: you just committed with a rubbish message, pleases amend it to make sense for your project.

Slide 71

Slide 71 text

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.

Slide 72

Slide 72 text

Notice: empty folder won't be committed!

Slide 73

Slide 73 text

if you still want to commit an empty folder, you can put an empty “.gitkeep” file in it by convention.

Slide 74

Slide 74 text

git log

Slide 75

Slide 75 text

git log --pretty=oneline

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

git help log

Slide 78

Slide 78 text

Exercise: check your commit log

Slide 79

Slide 79 text

Exercise: read the help manual of “git log”, and make your prefer log format.

Slide 80

Slide 80 text

Exercise: modify something in the "world.rb" then commit again.

Slide 81

Slide 81 text

git rm

Slide 82

Slide 82 text

Exercise: remove a file and then checkout it back.

Slide 83

Slide 83 text

git tag

Slide 84

Slide 84 text

tag is a milestone

Slide 85

Slide 85 text

Exercise: create a tag for your project

Slide 86

Slide 86 text

git branch

Slide 87

Slide 87 text

branching is very cheap

Slide 88

Slide 88 text

When to make a Branch?!

Slide 89

Slide 89 text

git checkout

Slide 90

Slide 90 text

Exercise: 1. create a new branch name "fruit" 2. checkout to "fruit" branch 3. add a "banana.rb" and commit it

Slide 91

Slide 91 text

Exercise: please try to list all branches, including local and remote branches.

Slide 92

Slide 92 text

Exercise: you accidentally delete the "world.rb" file, please try to recover it with git commands.

Slide 93

Slide 93 text

Exercise: you just create a tag name “ncku”, try to checkout to this tag after several commits.

Slide 94

Slide 94 text

git merge

Slide 95

Slide 95 text

conflict?

Slide 96

Slide 96 text

Exercise: 1. checkout back to "master" branch 2. merge "fruit" to "master" 3. remove "fruit" branch if you like

Slide 97

Slide 97 text

git reset soft v.s. hard

Slide 98

Slide 98 text

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

Slide 99

Slide 99 text

Exercise: you just merged a branch, please try reset it to back to un-merged branch.

Slide 100

Slide 100 text

git pull

Slide 101

Slide 101 text

git pull = git fetch + git merge

Slide 102

Slide 102 text

git push

Slide 103

Slide 103 text

git push origin ncku-branch

Slide 104

Slide 104 text

git clean remove untracked files

Slide 105

Slide 105 text

git stash apply, pop, list, clear

Slide 106

Slide 106 text

git remote

Slide 107

Slide 107 text

Reading References

Slide 108

Slide 108 text

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

Slide 109

Slide 109 text

Git Flow

Slide 110

Slide 110 text

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

Slide 111

Slide 111 text

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

Slide 112

Slide 112 text

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

Slide 113

Slide 113 text

Exercise: please install git flow in your machine, and initialize a git flow project.

Slide 114

Slide 114 text

init a project with git flow > git flow init

Slide 115

Slide 115 text

Branches Master, Develop, Feature, Release, Hotfix

Slide 116

Slide 116 text

add a new feature: > git flow feature start my_new_feature when done with the new feature: > git flow feature finish my_new_feature

Slide 117

Slide 117 text

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.

Slide 118

Slide 118 text

Exercise: your boss find a bug and ask you to fix it ASAP, please try to do this assignment in git flow.

Slide 119

Slide 119 text

Github

Slide 120

Slide 120 text

What's Github?

Slide 121

Slide 121 text

a git repository server

Slide 122

Slide 122 text

coders' facebook :)

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

make friends with other awesome coders :)

Slide 125

Slide 125 text

resume for coders!

Slide 126

Slide 126 text

Free? Price?

Slide 127

Slide 127 text

SSH/HTTPS/GIT

Slide 128

Slide 128 text

How to Github?

Slide 129

Slide 129 text

Exercise: register a new account on Github

Slide 130

Slide 130 text

without password?

Slide 131

Slide 131 text

SSH Key

Slide 132

Slide 132 text

Exercise: generate a SSH key pair in your local machine and add the public key to Github

Slide 133

Slide 133 text

Exercise: create a new repository on Github

Slide 134

Slide 134 text

git push

Slide 135

Slide 135 text

Exercise: upload your project to Github

Slide 136

Slide 136 text

Exercise: 1. clone a project from Github 2. do some changes 3. commit and push back to Github

Slide 137

Slide 137 text

Exercise: 1. create a new local branch 2. add some change and then push this branch to Github

Slide 138

Slide 138 text

tag won't be pushed to repo by default

Slide 139

Slide 139 text

push a tag: > git push origin v2.0 push several tags: > git push origin --tags

Slide 140

Slide 140 text

Exercise: create some tags for your project and upload them to Github

Slide 141

Slide 141 text

git pull

Slide 142

Slide 142 text

Fork

Slide 143

Slide 143 text

Pull Request

Slide 144

Slide 144 text

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.

Slide 145

Slide 145 text

Github Pages

Slide 146

Slide 146 text

host static files for FREE

Slide 147

Slide 147 text

upload files via git commands

Slide 148

Slide 148 text

User pages kaochenlong.github.io

Slide 149

Slide 149 text

Project Pages gh-pages branch

Slide 150

Slide 150 text

custom domain name

Slide 151

Slide 151 text

Exercise: 1. create a github page for your account. 2. set your domain name in CNAME if you have one.

Slide 152

Slide 152 text

something else?

Slide 153

Slide 153 text

bitbucket free private repo

Slide 154

Slide 154 text

git + dropbox

Slide 155

Slide 155 text

What's inside the .git folder?