git and github

26
Git & GitHub 12/30(Wed) Hypercomputer Seminar Taehwan Kim [email protected] http://fast.ajou.ac.kr

Upload: taehwan-kim

Post on 13-Jan-2017

44 views

Category:

Engineering


0 download

TRANSCRIPT

Git & GitHub12/30(Wed) Hypercomputer Seminar

Taehwan [email protected]

http://fast.ajou.ac.kr

DVCS ? CVCS ?• Git based on DVCS (Dis-

tributed Version Control System).• DVCS just mirrors full

repositories, unlike CVCS.• CVCS (Central Version

Control System) only checkouts file’s final snapshot.

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.

Snapshots, Not Differ-encesGit 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.

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

shot.

Diagram of Git states.

Files in your working direc-tory• Tracked: Already contains in snapshot. (above three

states, committed, (un)modified, staged.• Untracked: Your files don’t contain snapshot or

staging area.

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

RONMENTCAN

CANNOT

$ git clone1. Using HTTPS$ git clone https://github.com/username/foo.git

2. Using SSH$ git clone [email protected]:username/foo.git

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.

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

ter than remembering password.

How to generate SSH keys.• First, you should generate your public SSH key.

$ ssh-keygen • Many options for making key, but Now, we just be-

come 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

Register public key to GitHub

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

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.

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

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

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

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

ten.

Fast-Forward merge.When A merge to B, If B directs the commit which af -ter A, just A directs B’s commit.

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.

How to check CONFILCTS• After commit failed, you can know conflicted file.

$ git merge iss53Auto-merging index.htmlCONFILCT (content) : Merge conflict in index.htmlAutomatic merge failed; fix conflicts and then commit the result.• You also check unmerged file by ‘$ git status’ com-

mands

How to resolve CONFILCTSFirst, 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.

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

Thank you for listening!Read https://git-scm.com/book/ko/v2 and keep studying!