Engineering/Git
[Git] 01 Git Basic
iamzieun
2023. 4. 4. 17:41
Git & Github
- Git: 소프트웨어 버전관리 시스템(VCS, Version Control System)의 한 종류
- Git server & Git client
- git server
- 코드를 모아둔 중앙 서버
- ex) github.com, gitlab 등
- git client
- git server의 사본을 가진 로컬 환경
- ex) git CLI(Command-line interface), Visual Studio Code에 내장되어 있는 git 등
- git server
Create Repository
- Repository
- repository: 파일이나 디렉토리(폴더)를 저장하는 장소
- local repository: 자신의 컴퓨터에 있는 repository
- remote repository: 서버 등 네트워크에 있는 repository
Clone Repository
- Clone
- remote repository의 내용을 local repository에 다운로드
- git clone [url]
Git Init
- git init
- repository 초기화
Git Config
- git config
- 설정 쓰기
- git config <이름> <값>
git config --<범위> <이름> <값>
- git config <이름> <값>
- 설정 읽기
- git config <이름>
- 설정 지우기
- git config --unset <이름>
git config --global --unset <이름>
- git config --unset <이름>
- git config을 활용한 git 최초 설정: 8.1 Customizing Git - Git Configuration
- 설정 쓰기
Git Add / Commit / Push / Pull / Fetch / Merge
- add / commit / push
- add: 파일이나 디렉토리를 index에 추가
- commit: index에 추가된 파일이나 디렉토리의 내용을 local repository에 작성
- 각각의 commit(=버전)은 그 commit이 만들어진 stage area의 snapshot이다 → 언제든지 과거에 그 commit을 만든 시점으로 돌아갈 수 있다.
git commit -m "커밋메시지"
- -m
git commit -a -m "커밋메시지" git commit -am "커밋메시지"
- -a: tracked 상태의 파일을 auto adding. untracked 상태의 파일은 add하지 않음
- tracked / untracked
- m: modified. tracked
- u: untracked → 한 번도 add하지 않은 파일
- add vs -a
- add: untracked → tracked
- -a: tracked만 add
- push: local repository의 commit을 remote repository에 반영하는 작업
- pull / fetch / merge
- pull: ****remote repository의 commit을 local repository에 반영하는 작업
- fetch + merge
- fetch: remote repository의 commit을 local repository로 가져오는 작업
- merge: 두 branch를 병합
- pull: ****remote repository의 commit을 local repository에 반영하는 작업
Head
- 새로 만들어진 commit은 head가 가리킨다.
- head가 가리키는 commit이 새로 만들어진 commit의 부모이다
- head는 working directory와 stage area가 어떤 버전인지 알려준다
- checkout은 head를 바꾼다.
Git Remote
- remote: remote repository를 조작하는 기능
- 현재 프로젝트의 remote repository 목록 표시
git remote
- remote repository 추가
git remote add <이름> <url>
- remote repository 제거
git remote rm <이름>