< 수강분량 : Git CH. 1 ~ 10 >
Working Directory (작업공간) - 실제 소스 파일, 생성한 파일들이 존재
Index (Stage) - Staging area (준비영역) 의 역할, git add 한 파일들이 존재
HEAD - 최종 확정본, git commit 한 파일들이 존재
# Workspace 생성
% mkdir git_ws
# Working Directory 생성
% cd git_ws
git_ws % mkdir test_project
# Git init
# 폴더에서 Git 을 초기화하는 명령어를 사용하면 해당 폴더를 Git이 관리하기 시작
test_project % git init
# .git 확인
test_project % ls -all
# 파일 생성
test_project % touch test.txt
test_project % ls
test.txt
# Git status
# Git 에 존재하는 파일 확인
test_project % git status
# Git Add
# Working Directory 에서 변경된 파일을 Index (stage)에 추가
# git add <file name>
test_project % git add test.txt
# Git Commit
# Index (stage) 에 추가된 변경사항을 HEAD 에 반영 (확정)
# git commit -m "commit 에 대한 설명" <filename>
test_project % git commit -m "first commit" test.txt
1) GitHub 에서 생성
2) Local Repository 에 연동할 Remote Repository 를 등록 (Token 사용)
# Remote Reposiitory 등록 with Username and Token
git remote add origin https://<username>:<token>@github.com/<repository>.git
# 확인
test_project % git remote -v
# Git Push
# git push origin <branchname>
# master 안되면 main
test_project % git push origin master
# Git Pull
# git pull origin <branchname>
# master 안되면 main
test_project % git pull origin master
git clone https://<username>:<token>@github.com/<repository>.git
# Branch 조회 (Local Branch)
git branch
# Branch 조회 (Remote Branch)
git branch -r
# Branch 조회 (Local + Remote Branch)
git branch -a
# Branch 생성
git branch <branchname>
# Branch 이동
git checkout <branchname>
# Branch 생성 + 이동
git checkout -b <branchname>
# Branch 생성 (Remote Repository 에 넣기)
git push origin <branchname>
# Branch 삭제 (Local Repository)
# 해당 위치에서는 삭제가 안되니 필요시 다른 branch로 이동
git branch -d <branchname>
# Branch 삭제 (Remote Repository)
git push origin --delete <branchname>
git log
git config --global core.editor <editorname> --wait
# Git Configuration 파일 열기
git config --global -e
# Git Diff 설정 추가
[diff]
tool = vscode
[difftool "vscode"]
cmd = "code --wait --diff $LOCAL $REMOTE"
# Git Diff - Local Branch 간 비교
git diff <branch1> <branch2>
git difftool <branch1> <branch2>
# Git Diff - Commit 간 비교
git diff <commithash> <commithash>
git difftool <commithash> <commithash>
# Git Diff - 마지막 Commit 과 이전 Commit 비교
git diff HEAD HEAD^
git difftool HEAD HEAD^
# Git Diff - 마지막 Commit 과 현재 수정사항 확인
git diff HEAD
git difftool HEAD
# Git Diff - Local and Remote 간 비교
git diff <branch> origin/<branch2>
git difftool <branch> origin/<branch2>
# Git Configuration 파일 열기
git config --global -e
# Git Merge 설정 추가
[merge]
tool = vscode
[mergetool "vscode"]
cmd = "code --wait $MERGED"
# Git Merge
# 현재 위치한 Branch 에 다른 Branch 병합
git merge <branchname>
# MergeTool 실행
# Conflict 발생 이후 아래와 같이 MergeTool 을 실행하면 Conflict 난 파일들이 차례로 열림
git mergetool
# Conflict 해제
# git add + git commit
git add <filename>
git commit
# 현재 버전에 Tag 달기
git tag <tagname>
# 특정 버전에 Tag 달기
git tag <tagname> <commithash>
# Tag 를 Remote Repository 에 Push
git push origin <tagname>
# Git Tag 목록 보기
git tag
# Git Tag 상세 정보
git show <tagname>
# Git Tag 삭제 (Local)
git tag --delete <tagname>
# Git Tag 삭제 (Remote)
git push --delete origin <tagname>
"이 글은 제로베이스 데이터 취업 스쿨의 강의 자료 일부를 발췌하여 작성되었습니다."