Upload
geunhyung-kim
View
151
Download
0
Embed Size (px)
Citation preview
Geun-Hyung Kim UMCL @ Dong-Eui University
Introduction to Git/GitHub
버전�관리�시스템�
Local�Version�Control�/�Central�Version�Control�/�Distributed�Version�Control�
Git�-�Basic�
Git�-�Tutorial�:�Just�doing�small�work�with�Git�
Configuration�
Create�Repository�
Git�Workflow�
GitHub�-�Tutorial:�Just�doing�small�work�with�remote�storage�
Create/Delete�Repository��
Create�branch��
Open�Pull�Request�/Merge�Pull�Request
목�차담고�있는�내용
Version�Control�SystemWhat�is�Version�Control?
A�category�of�software�tools�that�help�a�software�team�manage�
changes�to�source�code�over�time.��
(소프트웨어�개발�팀이�개발�중에�소스코드의�변경�관리를�돕는�소프트
웨어�도구)
버전�관리�시스템
모든�파일�변화를�시간에�따라�버전�관리�데이터베이스에�기록한�후�나중에�특정�
시점의�버전을�다시�꺼내올�수�있는�시스템
그래픽�디자이너나�웹�디자이너도�버전�관리�시스템(VCS�-�Version�Control�System)을�사용�가능�
VCS로�이미지나�레이아웃의�버전(변경�이력�혹은�수정�내용)을�관리하는�것이�현명
각�파일을�이전�상태로�되돌릴�수�있음�
프로젝트�전체를�이전�상태로�되돌�수�있음�
시간에�따라�수정�내용을�비교해�볼�수�있음�
누가�문제를�일으켰는지�추적��
VCS를�사용하면�파일�잃거나�잘못�수정되었을�때�쉽게�복구�
Benefits�(장점)�
A�complete�long-term�change�history�of�every�file�
파일�생성,�삭제,�변경과�같은�파일�변경에�대한�전체�히스토리를�기록하고�있어�과거의�임의의�버전을�이용�가능��
Branching�and�merging�
�branch(브랜치)�생성�기능을�이용하여�팀원이�독자적인�개발을�수행�
각�개발자들이�각�브랜치의�수정에서�서로�충돌이�발생하는지�검증�
수행�결과를�통합하여�최종�개발의�배포�버전을�결정���
Traceability�
각�변경에�대한�목적과�의도를�설명하는�주석을�적을�수�있도록�하여�파일�변경에�대해�추적이�가능
Version�Control�SystemWhat�can�we�do�with�VCS?
간단한�로컬�데이터베이스를�사용하여�파일의�변경�정보를�관리�
�RCS�(Revision�Control�System):�파일에서�변경된�부분�(Patch�Set)을�특별한�형식의�파일로�저장하여�파일의�특정�시점으로�되돌릴�수�있음�
Version�Control�SystemLocal�Version�Control
Check-in
Check-out
<source:�https://git-scm.com/book/en/v2/Getting-Started-Git-Basics>
다른�개발자와�함께�작업을�하며�작업에�대한�버전�관리를�위해�네트워크에�서버를�이용하는�방법�(예:�CVS,�Subversion,�Perforce��같은�시스템�)�
장점:�프로젝트에�참여하는�개발자�누가�무엇을�하고�있는지�관리�용이,�하나의�VCS로�관리�가능�
단점:�중앙의�서버가�문제가�발생하면�백업을�할�방법이�없음�
Version�Control�SystemCentralized�VCS�(CVCS)
<source:�https://git-scm.com/book/en/v2/Getting-Started-Git-Basics>
Check-in (Commit)
Check-out
Check-in (Commit)
Check-out
Version�Control�SystemDistributed�VCS�(DVCS)저장소�전체를�로컬�호스트로�복사한�후�작업을�수행하며�버전�관리를�수행,�협업이�필요할�때�네트워크�서버를�이용�
Check-in��(Commit) Check-out
pull(clone) push
장점:��
네트워크의�서버에�장애가�발생해도�개별�개발자의�작업을�로컬�컴퓨터에서�진행�가능�
다양한�형태의�워크플로우�가능��
단점:�
바이너리�데이터를�저장하여야�하는�경우�저장�공간을�많이�차지��
히스토리가�많은�경우�다운로드하고�업로드하는데�많은�시간�소요��
예:�Git,�Mecurial,�Bazaar�등
<source:�https://git-scm.com/book/en/v2/Getting-Started-Git-Basics>
Git - Basic
Developed�as�the�version�control�system�for�Linux�Kernel�Project�(리눅스�커널�프로젝트를�위한�버전�관리�시스템으로�개발)��
Birth�year:�2005년��
Initial�purpose�(초기�목표)�speed�(빠른�속도)�
simple�design�(단순한�구조)�
strong�support�for�non-linear�development�(thousands�of�parallel�branches)��
������(동시�다발적인�브랜치를�통한�비선형적인�개발)�
fully�distributed�(완벽한�분산)�
capable�of�handling�large�projects�efficiently��
������(리눅스�커널�같은�대형�프로젝트�효율적인�지원)
GitHistory
Linus Torvards
Git�thinks�about�its�data�more�like�a�stream�of�snapshots.��(Git은�데이터를�스냅샷들의��스트림으로�고려)�
Every�time�you�commit,�or�save�the�state�of�your�project�in�Git,�it�basically�takes�a�picture�of�what�all�your�files�look�like�at�that�moment�and�stores�a�reference�to�that�snapshot.�(데이터를�가져오거나�프로젝트를�저장할�때마다�그�시점의�파일에�대해서�스냅샷을�구한�후�그�것에�레퍼런스를�저장)�
To�be�efficient,�if�files�have�not�changed,�Git�doesn’t�store�the�file�again,�just�a�link�to�the�previous�identical�file�it�has�already�stored.�(변경되지�않은�파일은�다시�파일을�저장하지�않고�이전에�저정한�동일한�파일을�링크)
GitBasic:�snapshot
<source:�https://git-scm.com/book/en/v2/Getting-Started-Git-Basics>
Everything�is�check-summed�before�it�is�stored�and�then�is�referred�to�by�that�checksum�(데이터를�저장하기�전에�체크섬을�구하며�이�체크섬을�통해�데이터를�관리)�
Git�uses�a�SHA-1�hash�for�this�checksumming�(체크섬�계산은�SHA-1��해시�사용)��40-character�string�composed�of�hexadecimal�characters�(16진수�문자�(0,�1,..,�9,�a,b,.,,f)로�구성된�40개의�문자열)�
calculated�based�on�the�contents�of�a�file�or�directory�structure�(파일의�내용�또는�디렉토리�구조를�기반으로�계산)�
Git�stores�everything�in�its�database�not�by�file�name�but�by�the�hash�value�of�its�contents�(데이터베이스에�파일�이름이�아닌�파일�콘텐츠의�해시�값을�저장)
GitBasic:�checksum
hash�value�example
Three�main�sections(세개의�영역)�Working�directory�(작업�공간):�a�single�checkout�of�one�version�of�the�project�(프로젝트의�특정�버전의�파일들로�저장소에�압축�파일을�가져와�작업을�할�수있는�장소)�
Staging�Area�(집결지):�a�file,�generally�contained�in�your�repository,�that�stores�information�about�what�will�go�into�your�next�commit�(다음�커밋할�것에�대해서�정보를�저장하고�있는�파일�-�일반적으로�저장소에�저장)�
Repository�(저장소):�stores�the�metadata�and�object�database�for�your�project�(프로젝트의�메타데이터와�객체�데이터베이스를�저장하는�곳)
GitBasic:�three�sections�/�states
checkout
WorkingDirectory
StagingArea
Repository
add commit
Git�has�three�main�states�that�your�files�can�reside�in�(Git은��파일을�세�가지의�상태로�관리)�Committed:�the�data�is�safely�stored�in�your�local�database�(데이터가�저장소에�안전하게�저장된�상태)�
Staged:�you�have�marked�a�modified�file�in�its�current�version�to�go�into�your�next�commit�snapshot�(현재�버전에서�수정된�파일을�다음�버전에�저장하기�위해�표시한�상태)�
Modified:��you�have�changed�the�file�but�have�not�committed�it�to�your�database�yet�(파일을�수정을�하였으나�아직�저장소에�저장소에�저장되지�않은�상태)
GitBasic:�three�sections�/�states
(committed state)
(staged state)(modified state)
<source:�https://git-scm.com/book/en/v2/Getting-Started-Git-Basics>
1. modify�files�in�your�working�directory�(워킹�디렉토리에서�파일을�수정)�
2. stage�the�files,�adding�snapshots�of�them�to�your�staging�area�(staging�영역에�파일의�스냅샷을�생성하여�추가)�
3. do�a�commit�(staging�영역을�파일을�저장소에�저장)
GitBasic:�Simple�Workflow
Just�go�to�http://git-scm.com/download/win��(automatic�download)
Git�Install�Git�for�Windows
go�to�https://git-for-windows.github.io/
GitInstall�Git�for�Windows
Git�BashGit�GUI
Shell�Integration
Just doing small work with Git
Configuration
Git�Work�flow
Create�Repository
Git�-�Tutorial�Configuration
Git은�설치�후�사용환경을�설정하면�나중에�Git�사용�시�반영�
Git을�업그레이드�하여도�설정�내용은�유지�
git�내부�명령어
$ git config�을�이용해서�설정�내용을�확인�또는�변경
관련�설정�파일�/etc/gitconfig�파일:�시스템의�모든�사용자와�모든�저장소에�적용되는�설정��
$�git config --system�옵션으로�이�파일을�수정�
~/.gitconfig,�~/.config/git/config�파일:�특정�사용자에게만�적용되는�설정�
$ git config --global 옵션으로�이�파일을�수정�
.git/config�파일:�Git�디렉토리에�있고�특정�저장소(혹은�현재�작업�중인�프로젝트)에만�적용�
$ git config --local 옵션으로�이�파일을�수정�
적용�순서:�프로젝트�->�사용자�->�시스템의�순으로�적용
Windows�에서는�$HOME�디렉토리�(아마도�C:\Users\$USER�디렉토리)에�.gitconfig�파일
Git�-�Tutorial�Configuration
$ git config user.name “Geun-Hyung Kim”
$ git config user.email [email protected]
$ git help configconfig (git 내부 명령어) 에 대한 설명 요청
$ git config user.name “Geun-Hyung Kim”
$ git config user.email [email protected]
$ git help configconfig (git 내부 명령어) 에 대한 설명 요청
…
Git�-�Tutorial�Create�Repository
$git init:
현재�디렉토리를�확인하는�명령어
gitstore라는�새로운�디렉토리를��생성하는�명령어
gitstore�디렉토리로�이동
현재�디렉토리가�geunkim�밑의�gitstore��디렉토리임을�나타냄
현재�디렉토리의�내용을�확인하는�명령어
git��저장소�(.git�하위�디렉토리�생성)�를�초기화하는�명령어
~/gitstore/.git��저장소를�초기화
git�metadata를�저장하는�디렉토리
.git�디렉토리를�만들고�저장소에�관련한�metadata를�저장.�이�.git�디렉토리가�있는�
working directory에서 git 명령어를 실행할 수 있는 상황이 됨
Q)�다른�프로젝트에�참여하거나�Git�저장소를�복사해�오고�싶을�때는�?�
Windows�에서는��cd를�사용
Git�-�Tutorial�Working�Directory에서�작업
working�directory�내�파일�상태�확인
$ git status:working�directory와�repository의�상태를�체크,�어떤�파일이�working�directory�에�있는지,�commit이�필요한�변경사항이�있는지�등을�확인
working�directory의�tracked와�untracked로�나뉨�untracked�file�은�아직�git�관리�대상이�아닌�파일�
tracked�file은�git에�의해서�관리되는�파일�(이미�저장소나�staging�area에�있는�파일)
create�README.txt��file�
add�the�file�to�staging�area�
commit�changes�
modified�README.txt�and�create�new�LICENSE�
add�both�files�to�stage�area�
commit�changes
Git�-�Tutorial�Git�Workflow
Git�-�Tutorial�Git�Workflow:�create�README.txtvi�편집기를�이용하여��README.txt�파일�생성�
현재�디렉토리�내용�확인�
최근�commit�이후로�변경사항�확인관리되지않는�파일�목록
commit하기�위해�추가된�것은�없으나�untracked�file이�존재한다
새롭게�생성된�파일
Git�-�Tutorial�Git�Workflow:�add�file�to�staging�area
README.txt�파일을��staging�area에�add�
commit�될�파일�목록
staging�area에�있는�파일
Git�-�Tutorial�Git�Workflow:�commit�changes
staging�area의�파일을�저장소에�저장
이�파일에�대해서�무엇을�하였는지�간단한comment�내용version�control�master
staging�area와�working�directory�파일�없음
Git�-�Tutorial�Git�Workflow:�modifies�README.txt�adds�LICENSE
README.txt�파일�수정�
LICENSE�파일�새롭게�생성
master�branch�에서
tracked�file�중�수정이�된�파일
�untracked�file
Git�-�Tutorial�Git�Workflow:�add�files�to�staging�area
�수정�파일/새�파일�모두�추가
$�git�add�README.txt�LICENSE��와�동일
Git�-�Tutorial�Git�Workflow:�commit�changes
Git�-�Tutorial�Git�TimeLine�History
$git log:�저장소의�commit�히스토리를�시간�순으로�보여줌,��가장�최근에�commit한�것이�가장�먼저�출력
master
To�discard�changes�in�working�directory��[working�directory에서�변경�내용을�무시(삭제)�하려면
Git�-�Tutorial�check�out
$ git checkout -- <fileName>
Git�-�TutorialWeb�Programming�-�Workflow
4�개�파일을�작성한�후�git�status�한�결과�화면�
4�개�파일을�staging�area로�추가한�결과
Git�-�TutorialWeb�Programming�-�Workflow
4�개�파일을�repository에�저강한�상태
repository�상태�체크�
Just doing small work with Remote Storage
(GitHub)
What�is�GitHub�?�
Create�a�Repository�
Create�a�Branch�
Make�and�Commit�Changes�
Open�a�Pull�Request�
Merge�a�Pull�Request
GitHub�-�Tutorial
<�source:�https://guides.github.com/activities/hello-world/�>
a�code�hosting�platform�for�version�control�and�collaboration��
(버전�관리와�협업을�위한�파일(code)�호스팅�플랫폼)�
It�lets�you�and�others�work�together�on�project�from�anywhere�
(어디에서는�프로젝트에�협업이�가능하도록�함)
GitHub�-�TutorialWhat�is�GitHub?
master
GitHub�(Remte�Repository)
pushpull
pull
<�source:�https://guides.github.com/activities/hello-world/�>
1. 오른쪽�위의�+�메뉴를�선택한�후�“New�repository”�를�선택�
2. 저장소�이름을�hello-world�로�정한다.�
3. 짧은�설명을�작성�
4. “Initialize�this�repository�with�a�README”�를�선택�
5. Create�repository를�클릭
GitHub�-�TutorialCreate�Repository
repository 생성을 메뉴
<�source:�https://guides.github.com/activities/hello-world/�>
GitHub�-�TutorialCreate�Repository
<�source:�https://guides.github.com/activities/hello-world/�>
1. 삭제하려는�저장소를�선택�
2. �����������������(설정)�탭을�선택�
3. 화면의�아래에�있는�������������������������버튼을�클릭�
4. 삭제할�저장소�이름을�입력�후�삭제
GitHub�-�TutorialDelete�Repository
GitHub�-�TutorialCreate�a�Branch
Branching:�저장소의�다른�버전에서�작업을�하는�방법�기본적으로�저장소는�최종�버전(최종�branch)인�master라는�하나의�branch를�가짐�
master에�commit하기�전에�테스트를�하기�위해�여러�branch를�사용�
master에서�branch를�생성하면�그�시점의�master�복사�또는�스냅샷을�생성�
‘master’�branch
Create�‘feature’�branch�from�‘master’ Merge�‘feature’�branch�into�‘master’
Commit�changes Submit�Pull�Request Discuss�proposed�changes
<�source:�https://guides.github.com/activities/hello-world/�>
1. 새로운�hello-world�저장소를�선택�
2. “branch:�master”�라는�파일�목록의�위에서�drop�down을�클릭�
3. 새로운�branch�text�box에�branch�이름을�readme-edits로�입력��
4. 파란색의�Creat�branch�box를�선택하고�“return”�키�입력
GitHub�-�TutorialCreate�a�Branch
<�source:�https://guides.github.com/activities/hello-world/�>
GitHub�-�TutorialCreate�a�Branch
branch�목록
현재�branch
주�branch
readme-edit�branch�에서�README.md�파일을�클릭�
파일�수정을�위해�file�view의�오른쪽�상단의�연필�icon을�클릭�
editor에서�내용을�수정�
변경�내용을�설명할�commit�message를�작성�
Commit�changes�버튼을�클릭
GitHub�-�TutorialMake�and�commit�changes
<�source:�https://guides.github.com/activities/hello-world/�>
Pull�Requests:�GitHub의�협업의�핵심�
Pull�request는�개인적으로�변경한�내용을�협업자들에게�알려�리뷰
를�요청하고�협업자들의�branch에�merge할�것을�요청�
Pull�request는�branch들�간의�차이점을�나타냄�(추가된�것:�녹색,�
삭제한�것:�빨간색)�
commit한�후�코드�개발이�종료되지�전에�pull�request를�open하
여�논의�시작�가능
GitHub�-�TutorialOpen�a�Pull�Request
<�source:�https://guides.github.com/activities/hello-world/�>
1. Pull�requests�tab을�클릭한�후�녹색의�New�pull�request�버튼을�클릭
GitHub�-�TutorialOpen�a�Pull�Request
2. master�branch와�비교할��branch�(readme-edits)를�선택
<�source:�https://guides.github.com/activities/hello-world/�>
3. 수정�사항과�master와의�차이를�보면서�최종�제출�여부�확인�
GitHub�-�TutorialOpen�a�Pull�Request
<�source:�https://guides.github.com/activities/hello-world/�>
4. 변경사항에�문제가�없으면�Create�Pull�Request�버튼을�클릭
GitHub�-�Tutorial
5. 변경사항에�대한�설명�제목과�간단한�설명을�남기고��Create�Pull�
request!�버튼�클릭
Open�a�Pull�Request
<�source:�https://guides.github.com/activities/hello-world/�>
GitHub�-�TutorialMerge�a�Pull�Request
readme-edits�branch를�master�branch에�함께�merge하는�단계
1. 변경�내용을�master에�추가하기�위해서�Merge�pull�request�버튼을�클릭�
2. Confirm�merge�클릭�
3. 변경사항을�추가하였기�떄문에�branch를�삭제하기�위해서�Delete�
branch�버튼을�클릭
<�source:�https://guides.github.com/activities/hello-world/�>
Local�repository와�GitHub�repository�연결하기�
Local�Git에�remote�repository�추가
GitHub�-�TutorialLocal�and�Remote�Repository
$git remote add origin https://github.com/username/myproject.git
본인의��GitHub�사용자�이름�(id)
연결하려는�저장소�이름�(이경우�myproject)
$git remote add [단축이름] [url]
remote�repository�
추가
url�로�표현되는�remote�repository��저장소의�단축이름
remote�repository의�url
단축이름이�origin�임
Local�repository와�GitHub�repository�연결하기
GitHub�-�TutorialLocal�and�Remote�Repository
github의�github.com/geunhkim/WebProgramming.git을�origin이라는�이름으로�추가�
Local�repository에�추가된�remote�repository�확인
$git remote
결과
Local�repository에�추가된�remote�repository�상세�정보
GitHub�-�TutorialLocal�and�Remote�Repository
Local�repository의�내용을�Remote�Repository에�upload�하기
Local의�내용을�overwrite�하기
push할�권한을�가지고�있지�않는�프로젝트에�참여하고자�할�경우에는�프로젝트를�“fork”를�
하여야�함�
“fork”하면�GitHub이�프로젝트를�통째로�사용자의�네임스페이스로�복사하기�떄문에�push를�
할�수�있음
GitHub�-�TutorialContributing�to�a�project
참여할�프로잭트의�Fork�button을�클릭하면�자신의�네임스페이스로�복사됨�
geunkim/WebProgramming에서�geunhyung/WebProgramming
으로�fork된�내용
GitHub�-�TutorialContributing�to�a�project
geunhyung�네임스페이스의�변경사항�비교�화면
GitHub�-TutorialContributing�to�a�project
geunkim�네임스페이스의�pull�request�된�결과
GitHub�-�TutorialContributing�to�a�project
GitHubWeb�Programming�Repository
https://github.com/geunhkim/WebProgramming.git
References버전관리를�들어본적�없는�사럼�들을�위한�DVCS�-�Git:�http://
www.slideshare.net/ibare/dvcs-git�
Git을�이용한�협업�워크플로우�배우기:�http://blog.appkr.kr/learn-n-think/
comparing-workflows/�
Become�a�git�guru:�https://www.atlassian.com/git/tutorials�
트라비스�스위스굿,�Git,�분산버전�관리�시스템,�(인사이드)�
git�—�everything-is-local:�https://git-scm.com/doc�
Pro�Git�book:�https://git-scm.com/book/en/v2�(한글�버전�존재)�
Giancarlo�Lionetti:�What�is�Version�Control:�Centralized�vs.�DVCS�
Adding�an�existing�project�to�GitHub�using�command�line:�https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/