2. DVCS ? CVCS ?
• Git based on DVCS
(Distributed Version
Control System).
• DVCS just mirrors full
repositories, unlike
CVCS.
• CVCS (Central Version
Control System) only
checkouts file’s final
snapshot.
3. Why should you use Git?
• If you use a SVN, you will lose all history when main server is
damaged. You can recover only your final snapshot.
• But If you use a Git, recovering is very easy because you just
choose one of the repositories. (think previous slide’s image)
• DVCS environment can have multiple remote repositories,
so you can work together various group and people.
4. Snapshots, Not Differences
Git don’t save difference of file, just take a picture of
file at that moment. Git thinks about its data more
like a stream of snapshots.
5. Git has the three states.
1. ‘Committed’ means that the data saved safely on the
repo.
2. ‘Modified’ means that you have changed the file but
have not committed it to your repo.
3. ‘Staged’ means that you have marked a modified file
in its current version to go into your next commit
snapshot.
7. Files in your working directory
• Tracked: Already contains in snapshot. (above three
states, committed, (un)modified, staged.
• Untracked: Your files don’t contain snapshot or
staging area.
8. Git: GUI vs CLI ??
• Today’s seminar’s goal is becoming skillful for using
Git in terminal environment.
• The command line(CLI) is the only place you can
run all Git commands.
USING GIT WELL IN
GUI ENVIRONMENT
USING GIT WELL IN
TERMINAL
ENVIRONMENT
CAN
CANNOT
9. $ git clone
1. Using HTTPS
$ git clone https://github.com/username/foo.git
2. Using SSH
$ git clone git@github.com:username/foo.git
10. 1. Clone repo. Using HTTPS
• Authentication with username and password.
• You don’t have to set anything.
• But you should type username and password every
time when push, pull, fetch.
• You can use a credential storage but I think that its
setting is more complex than SSH.
11. 2. Clone repo. Using SSH
• Auth. and send data using SSH protocol.
• Most of operating systems have SSH daemon and
management tools. So, setting is very easy.
• But, you should register public key to git hosting
server EACH DEVICES.
• From my experience, I think that register key is
better than remembering password.
12. How to generate SSH keys.
• First, you should generate your public SSH key.
$ ssh-keygen
• Many options for making key, but Now, we just
become YESMAN. (more information)
• Copy your public key to clipboard. Your key files is
in ~/.ssh/id_rsa.pub
• Turn on your Internet Browser and go to
http://github.com
14. Remote repository ?
• After clone project. Your local git repo has ‘origin’
remote repo.
• How to check remote repo?
$ git remote –v # show URL and remote name
• You can add more remote repo.
$ git remote add <name> <URL>
• Therefore, you can use multiple protocol using
above commands.
• More information
15. Checkout? Remote Branch?
• After clone repo, your current branch is ‘master’
and there is no local branch.
• But you want to work at ‘foo’ branch which your
co-worker worked before.
• How to move that branch?
$ git checkout origin/foo –b foo
• origin/foo is a remote branch of origin (remote
repo) and foo is your local branch.
16. $ git checkout
• You can move branch and restore something.
• In other words, ‘git checkout origin/foo’ means
now you want to move to origin/foo branch.
• ‘-b’ option means making new branch while moving.
• Q. Why not just type ‘git checkout –b origin/foo’?
• If your working directory is dirty, you should
arrange your directory. (more info..)
• If you change branch using checkout, your working
directory will be changed.
17. $ git branch
• If you just want to make a new branch.
$ git branch testing
# foo1 also directs current working branch.
• How to determine current working branch?
Git has a pointer ‘HEAD’.
18. $ git log
• git log show commit histories.
• -2 , n : show only 2 .. n histories.
• --oneline : show each log one line.
• --decorators : show connected branch.
• --grep <string> : show histories contain <string>
• … many options.
19.
20. What is a branch?
• Git branch is just SHA-1 checksum files direct to
some commit.
• So, it is very easy to make or delete branch.
• Each branches save previous commit’s information.
• Therefore, developers make and delete branch
often.
21. Fast-Forward merge.
When A merge to B, If B directs the commit which
after A, just A directs B’s commit.
22. 3-Way merge.
• When current branch’s commit is not ancestor of
target branch’s commit.
• 3-Way merge occurs CONFILCT when two branch
modify same part of one file.
23. How to check CONFILCTS
• After commit failed, you can know conflicted file.
$ git merge iss53
Auto-merging index.html
CONFILCT (content) : Merge conflict in index.html
Automatic merge failed; fix conflicts and then
commit the result.
• You also check unmerged file by ‘$ git status’
commands
24. How to resolve CONFILCTS
First, open unmerged file by text editor.
HEAD means your current branch and below of
=====.. means your target branch. You just choose
contents each branches or write new contents.
25. Fetch vs Pull
• Fetch just sync with remote repo.
• Pull merges remote branch and download data
from remote repo at the same time.
(fetch + merge)
• Example
$ git fetch origin
# Just download data from remote repo.
$ git pull origin master
# Merge origin/master to master
26. Thank you for listening!
Read https://git-scm.com/book/ko/v2 and keep studying!