DS School Week 9-1 Git 사용 준비
오늘 학습 내용
- Git 사용준비
- Git Repository 강의 수강
학습 내용
1. Git 이론
- Git이란? 버전관리 시스템의 한 종류
- 버전관리(형상관리)
- 용어
- Version Control Systems (VCS)
- Configuration Management Systems
- 특징
- Source Data + History
- 협업, 작업추적, 복구 등이 가능
- Git의 등장 배경
- Local Version Control System
- Centralized Version Control System
- 협업이 가능해졌으나, 자신만의 버전관리가 되지 않음
- commit하는 순간 배포되어, 다수에게 버그 유발 가능
- CVS, SVN 등
- Distributed Version Control System
- commit 하더라도 개인 저장소 내 적용
- 자신만의 버전 관리 가능함
- 원하는 순간 배포(Push) 가능
- Mercurial, Git 등
- Git 기반 서비스
- Github : Git을 호스팅 해주는 웹 서비스
- Gitlab : 설치형 버전관리 시스템
2. Github 설치
- Homebrew 설치
: Install Command 복사
- Git 설치
% brew install git
- Git 버전 확인
% git --version
- Git Global Configuration
% git config --global user.name <username>
% git config --global user.email <email>
- CRLF 설정
: Line ending 문자
[윈도우]
% git config --global core.autocrlf true
[Mac]
% git config --global core.autocrlf input
- Default Editor 설정
% git config --global core.editor <editor>
- 전체 설정 확인
% git config --list
3. Git 기본 용어
- Repository : 프로젝트 단위의 여러 소스코드들이 모여있는 공간
- Local Repository
- Remote Repository
- Checkout : 특정 시점이나 Branch의 소스코드들로 이동하는 것
- Stage : 작업할 내용이 올라가는 임시 저장 영역
- commit : 작업 내용을 Local Repository에 저장하는 과정
- Tag : 임의의 commit 위치를 쉽게 찾을 수 있는 이정표
- Push : Local Repository 내용 중 Remote Repository에 반영되지 않은 commit을 Remote Repository로 보내는 과정
- Pull : Reomote Repository에 있는 내용 중 Local Repository에 반영되지 않은 내용을 가져와서 Local에 저장
- Branch : 특정 시점에서 분기하여 새로운 commit을 쌓을 수 있는 가지를 만드는 것. 모든 branch 는 master branch에 merge 됨.
- Merge : Branch를 다른 Branch와 합치는 과정
4. Repository
- Local Repository
- 구성
Working Directory ➔ add ➔ Index(Stage) ➔ commit ➔ HEAD
- 명령어
- git 생성/설치
% cd path
: Repository 경로로 이동
% git init
: 해당 폴더를 working directory 로 인식 후 관리
- git 설치 확인
% ls -all
- git에 존재하는 파일 확인
% git status
- Git Add
% git add <filename>
- Git Commit
% git commit -m 'message' <filename>
- Git Push
% git push <origin> <branchname>
- Git Pull
% git pull <origin> <branchname>
- Remote Repository
- 생성
- github → create repository
→ repository name (local repository 이름과 동일하게) → 주소 카피
- Github Tocken 발급
- Settings → Developer settings → Personal access tockens → Generate new tocken → 토큰 저장
※ README : 프로젝트 설명, 사용방법, 라이센스, 설치 방법 등 기재
.gitignore : Git 버전관리에서 제외할 파일 목록 지정
- Local ~ Remote 연동
- Local → Remote
- %
git remote add origin <https://github.com/<repository>.git>
- %
git remote add <origin> https://<username>:<tocken>@github.com/<repository>.git
- 확인
%git remote -v
- Remote → Local
- Git Clone
: Git init + Remote repository Pull
% git clone https://github.com/<repository>.git
% git clone https://<username>:<tocken> @github.com/<repository>.git
- Branch
- Default Branch : Master vs Main
- Github
개별 Repository 에서 변경 가능
Settings → Repository 에서 초기 세팅 변경 가능
- 명령어
- 브랜치 조회
(local) %git branch
(remote) %git branch -r
(local+remote) %git branch -a
- 브랜치 생성
(local)%git branch <branchname>
(remote)%git push origin <branchname>
- 브랜치 이동
%git checkout <branchname>
- 브랜치 생성 + 이동
%git checkout -b <branchname>
- 브랜치 Remote에 생성
- 브랜치 삭제
(local) %git branch -d <branchname>
(remote) %git push origin --delete <branchname>
- 파일 관리 터미널 명령어
- 생성 %
touch file
- 생성/덮어쓰기 %
cat > file
+ control D
- 추가하기 %
cat >> file
+ control D
- 읽어오기 %
cat file
다음 학습 계획
- Git 강의 수강 : Log, Merge, Tab, README