Slide 1

Slide 1 text

Ruby/Rails training course Git, Github, and Vim eddie@fju

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

Git

Slide 5

Slide 5 text

What's Git

Slide 6

Slide 6 text

version control system (VCS)

Slide 7

Slide 7 text

created by Linus Torvalds

Slide 8

Slide 8 text

Why version control?

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Why Git

Slide 12

Slide 12 text

free

Slide 13

Slide 13 text

fast & smaller footprint

Slide 14

Slide 14 text

commit v.s push

Slide 15

Slide 15 text

easy to co-work with others

Slide 16

Slide 16 text

Install Git

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Exercise: please install git in your machine.

Slide 19

Slide 19 text

How to Git

Slide 20

Slide 20 text

don't be afraid of command line tools

Slide 21

Slide 21 text

git clone

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

git init

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

working, staging, and repository

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

git status

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

git mv

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

git commit

Slide 34

Slide 34 text

Exercise: just commit it :)

Slide 35

Slide 35 text

commit message matters!

Slide 36

Slide 36 text

amend committed message

Slide 37

Slide 37 text

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

Slide 38

Slide 38 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 39

Slide 39 text

Notice: empty folder won't be committed!

Slide 40

Slide 40 text

git log

Slide 41

Slide 41 text

Exercise: check your commit log

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

git rm

Slide 44

Slide 44 text

Exercise: remove a file and then checkout it back.

Slide 45

Slide 45 text

git tag

Slide 46

Slide 46 text

Exercise: create a tag for your project

Slide 47

Slide 47 text

git branch

Slide 48

Slide 48 text

branching is very cheap

Slide 49

Slide 49 text

git checkout

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

git merge

Slide 54

Slide 54 text

conflict?

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

git reset soft v.s. hard

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

git pull

Slide 60

Slide 60 text

git push

Slide 61

Slide 61 text

git clean remove untracked files

Slide 62

Slide 62 text

git stash apply, pop, list, clear

Slide 63

Slide 63 text

some dotfiles

Slide 64

Slide 64 text

.gitconfig it should locate in your home directory

Slide 65

Slide 65 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 66

Slide 66 text

make some useful aliases

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

Reading References

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

Git Flow

Slide 72

Slide 72 text

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

Slide 73

Slide 73 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 74

Slide 74 text

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

Slide 75

Slide 75 text

Branches Master, Develop, Feature, Release, Hotfix

Slide 76

Slide 76 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 77

Slide 77 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 78

Slide 78 text

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

Slide 79

Slide 79 text

Github

Slide 80

Slide 80 text

What's Github?

Slide 81

Slide 81 text

a git repository server

Slide 82

Slide 82 text

coders' facebook :)

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

make friends with awesome coder :)

Slide 85

Slide 85 text

resume for coders!

Slide 86

Slide 86 text

Free? Price?

Slide 87

Slide 87 text

SSH/HTTPS/GIT

Slide 88

Slide 88 text

How to Github?

Slide 89

Slide 89 text

Exercise: register a new account on Github

Slide 90

Slide 90 text

without password?

Slide 91

Slide 91 text

SSH Key

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

Exercise: create a new repository on Github

Slide 94

Slide 94 text

git push

Slide 95

Slide 95 text

Exercise: upload your project to Github

Slide 96

Slide 96 text

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

Slide 97

Slide 97 text

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

Slide 98

Slide 98 text

tag won't be pushed to repo by default

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

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

Slide 101

Slide 101 text

git pull

Slide 102

Slide 102 text

Fork

Slide 103

Slide 103 text

Pull Request

Slide 104

Slide 104 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 105

Slide 105 text

Github Pages

Slide 106

Slide 106 text

host static files for FREE

Slide 107

Slide 107 text

upload files via git commands

Slide 108

Slide 108 text

User pages kaochenlong.github.io

Slide 109

Slide 109 text

Project Pages gh-pages branch

Slide 110

Slide 110 text

custom domain name

Slide 111

Slide 111 text

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

Slide 112

Slide 112 text

something else?

Slide 113

Slide 113 text

bitbucket free private repo

Slide 114

Slide 114 text

git + dropbox

Slide 115

Slide 115 text

Vim

Slide 116

Slide 116 text

I'm looking for a editor..

Slide 117

Slide 117 text

1. launch quickly 2. easy to navigate between files 3. and pretty syntax highlight

Slide 118

Slide 118 text

What's Vim?

Slide 119

Slide 119 text

it may look a little old-fashioned

Slide 120

Slide 120 text

but it can also be modern : )

Slide 121

Slide 121 text

So, Why Vim?

Slide 122

Slide 122 text

and, Why not Vim?

Slide 123

Slide 123 text

How to Vim?

Slide 124

Slide 124 text

Exercise: Install Vim in your machine. http://www.vim.org/download.php

Slide 125

Slide 125 text

.vimrc

Slide 126

Slide 126 text

if you want to use my .vimrc 1. clone from my Github repo 2. cd to cloned repo and execute install script 3. make symbolic link for vim 4. done!

Slide 127

Slide 127 text

https://github.com/kaochenlong/eddie-vim

Slide 128

Slide 128 text

Modes normal, visual, and edit mode

Slide 129

Slide 129 text

Modes Switch: 1. in normal mode, "i" or "a" or "o" to enter insert mode(i = insert, a = append, o = newline) 2. in insert mode, ESC or Ctrl+[ to enter normal mode 3. in normal mode, hit "v" or "V" to enter visual mode 4. in visual mode, hit ESC or Ctrl+[ to normal mode

Slide 130

Slide 130 text

ESC or Ctrl + [

Slide 131

Slide 131 text

No content

Slide 132

Slide 132 text

Exercise: launch Vim and switch between normal, visual, and edit mode.

Slide 133

Slide 133 text

Basic

Slide 134

Slide 134 text

- :w write to file. - :q exit Vim. - :tabe create a new tab. - gt to switch to next tab, gT to previous tab. (I map gt and gT to F7 and F8 in my vimrc) - :new to create a horizontal split window, :vnew or :vs to create a vertical split window.

Slide 135

Slide 135 text

- vi -o a.rb b.rb to open those two files at the same time with horizontal split window. - vi -O a.rb b.rb same as above, but in vertical split window. - vi -p a.rb b.rb to open files with tabs. - vi http://www.eddie.com.tw will read the source content into vim directly.

Slide 136

Slide 136 text

Movement

Slide 137

Slide 137 text

move cursor with h, j, k and l disable arrows if possible

Slide 138

Slide 138 text

- w or W to move cursor forward by a word, and b or B is backward. - 0 to back to the begin of the line, and $ is jump to the end. - fx will stop the cursor at the next "x" character in current line, and F is search backward.

Slide 139

Slide 139 text

- } will move cursor to next section, { move to last section. - vit will visually select content between the tag, while vat will even including the tag. - vi" will visually select content between current double quotes. - viw will select the current word.

Slide 140

Slide 140 text

- gg will move the cursor to the top of the current file, and G will jump to bottom. - zz, zb, zt - / search, n can jump to next matched result, and N will jump to last one. - * search the word on cursor.

Slide 141

Slide 141 text

Exercise: try to move cursor with hjkl keys, not arrow keys.

Slide 142

Slide 142 text

Buffers :ls, :bd, :b3, :b filename, :tab ba

Slide 143

Slide 143 text

Exercise: try to open several files, and switch between them with buffer commands.

Slide 144

Slide 144 text

Editing

Slide 145

Slide 145 text

- D to clear all content of current line after the cursor. - C like D, but enter insert mode. - dG will clear all content after the cursor, dgg will clear all content before the cursor. - x remove a character. - . to repeat last action. - dd to delete whole line. - 3dd to delete 3 lines.

Slide 146

Slide 146 text

- yy yank the whole line of the cursor. - 3yy yank 3 lines. - p paste content from register. - 4p paster content from register for 4 times. - = re-format - gg=G re-format whole file.

Slide 147

Slide 147 text

- dw, diw to delete the word in the cursor. - cw, ciw same as above, but enter insert mode. - r to replace current character. - J to concatenate current line with next line, 3J will concatenate next 3 lines. - > to add indentation, < to remove indentation.

Slide 148

Slide 148 text

Plugins

Slide 149

Slide 149 text

Pathogen nice plugin manager https://github.com/tpope/vim-pathogen

Slide 150

Slide 150 text

NERDTree A tree explorer https://github.com/scrooloose/nerdtree

Slide 151

Slide 151 text

SnipMate code snippets plugin, inspired by TextMate https://github.com/msanders/snipmate.vim

Slide 152

Slide 152 text

ctrlp Fuzzy file, buffer, mru, tag, etc finder https://github.com/kien/ctrlp.vim

Slide 153

Slide 153 text

surround.vim quoting/parenthesizing made simple https://github.com/tpope/vim-surround

Slide 154

Slide 154 text

powerline the ultimate vim statusline utility https://github.com/Lokaltog/vim-powerline

Slide 155

Slide 155 text

rails.vim Ruby on Rails power tools https://github.com/tpope/vim-rails

Slide 156

Slide 156 text

fugitive a git wrapper for vim https://github.com/tpope/vim-fugitive

Slide 157

Slide 157 text

vimwiki personal wiki for vim https://github.com/vim-scripts/vimwiki

Slide 158

Slide 158 text

ragtag https://github.com/tpope/vim-ragtag

Slide 159

Slide 159 text

Practicing!

Slide 160

Slide 160 text

References

Slide 161

Slide 161 text

http://blog.eddie.com.tw/screencasts/

Slide 162

Slide 162 text

and more practice.. : )

Slide 163

Slide 163 text

Tips

Slide 164

Slide 164 text

in terminal: 1. ctrl + z to stash vim, and type "fg" to bring it back. 2. ctrl + w to delete a word, ctrl + u to delete a whole line, both work in terminal and vim edit mode. 3. ctrl + r to find history commands fuzzily.