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.
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.