Git 등장 전에는 Source Folder + 실행파일을 버전별로 카피하여 관리함
-> 하루종일 개발한 코드가 컴퓨터가 다운되면서 날아가버릴 수 있음
(1) Local Version Control Systems : 내 컴퓨터에서 버전 관리 가능 -> 내 컴퓨터 하드가 날아가면 전체 코드 사라짐. 버전은 관리되지만, 협업은 여전히 어려움
(2) Centralized Version Control Systems : 중앙에서 관리하기
-> 협업이 가능해짐
-> commit하는 순간 배포되어 다수에게 버그 유발 가능 (서버는 바로 commit)
-> 인터넷이 안 되면 작업 불가능
-> 자신만의 version history를 가질 수 없음
(3) Distributed Version Control Systems : 분산 관리
-> commit하더라도 개인저장소 내에 적용됨 (다른 개발자에게 영향 없음)
-> 원하는 순간에 배포(Push) 가능
-> 오프라인에서도 작업 가능
-> 자신만의 version history를 가짐
버전관리 시스템의 종류
-> CVCS (중앙관리) - CVS, SVN, etc.
-> DVCS (분산관리) - Mercurial, Git, etc.
Git : SVN보다 빠른 속도와 많은 기능을 지원, 현재 많은 기업이 사용 중
git config --global user.name <username>
git config --global user.email <email>
git config --global core.autocrlf true
git config --global core.autocrlf input
-> CRLF : 줄바꿈 문자
Windows : CR (\r) + LF(\n)
Unix or Mac : LF (\n)
-> Windows 사용자와 Mac 사용자가 같은 Git Repository를 작업할 때, 코드에서 변경된 내용이 없어도 CRLF 차이로 인해 commit이 발생할 수 있음
git config --global core.editor <editor>
git config --list
git config <key>
Repository : 소스코드가 저장되어 있는 여러 개의 Branch가 모여있는 디스크상의 물리적 공간
-> Local Repository와 Remote Repository로 구분
Checkout : 특정 시점이나 Branch의 소스코드로 이동하는 것을 의미
-> Checkout 대상 - Branch, Commit, Tag
-> Checkout을 통해 과거 여러 시점의 코드로 이동이 가능
Stage : 작업할 내용이 올라가는 임시저장영역
-> 이 영역을 이용하여 작업한 내용 중 commit에 반영할 파일만 선별하여 commit 수행가능
Commit : 작업할 내용을 Local Repository에 저장하는 과정
-> 각각의 commit은 의미있는 변경단위이고, 변경에 대한 설명을 commit log로 남김
-> 권장 - commit을 아끼지 말 것! (게임 save하는 것처럼)
-> 참고 - commit 단위나 commit log format을 정해놓은 회사나 팀도 있음 (빌드 서버를 사용하는 경우)
Tag : 임의의 commit 위치에 쉽게 찾아갈 수 있도록 붙여놓은 이정표
-> Tag가 붙은 commit은 commit id(version) 대신 tag name으로 쉽게 checkout 가능
Push : Local Repository의 내용 중, Remote Repository에 반영되지 않은 commit을 Remote Repository로 보내는 과정
-> 권장 - Push하는 순간, 다른 개발자들도 영향을 받기 때문에 검증되지 않은 코드는 Push하지 않도록 함.
Pull : Remote Repository의 내용 중, Local Repository에 반영되지 않은 내용을 가져와서 Local Repository에 저장하는 과정
-> 다른 팀원이 변경하고 Push한 내용을 Local Repository에 가져올 수 있음
-> 참고 - Push 과정에서 Conflict(충돌)이 일어나서 Push가 거절된 경우, Pull을 통해 Remote Repository의 변경 내용을 Local Repository에 반영하여 Conflict를 해결한 뒤에 다시 Push를 시도해야 함
Branch : 특정 시점(commit단위)에서 분기하여 새로운 commit을 쌓을 수 있는 가지를 만드는 것
-> 개발의 주축이 되는 branch를 master branch (혹은 main branch)라고 함
-> 모든 branch는 최종적으로 다시 master branch에 merge(병합)되는 형식으로 진행됨
Merge : Branch의 반대개념으로, 하나의 Branch를 다른 Branch와 합치는 과정
-> Merge되는 두 Branch는 주종관계가 성립. ex) dev branch를 main branch에 merge
-> Merge되는 과정에서 Conflict(충돌)이 발생하는 경우, Diff를 수정하여 Conflict를 해결한 뒤 Merge를 진행할 수 있음
mkdir git_ws
-> mkdir : making directory
cd git_ws
mkdir test_project
cd test_project
git init
ls -all # 숨겨진 파일까지 모두 확인 가능한 명령어
touch test.txt
ls # 확인해보기
git status
git add <filename>
git commit -m "commit에 대한 설명" <filename>
Github에서 'Create Repository' 버튼 클릭
Github Token 생성
: 얼마전부터 보안상의 이유로 Remote Repository 접속시 비밀번호 대신 Token을 사용
Remote Repository 등록
: Local Repository에 연동할 Remote Repository를 등록 (Token 사용)
git remote add origin https://github.com/MJLOO/test_project.git
git remote add origin https://<username>:<token>@github.com/MJLOO/test_project.git
-> 이렇게 등록하면 매번 유저네임과 토큰을 입력할 필요가 없어짐
git remote -v
git push origin <branchname>
git push origin master/main
Remote Repository 확인
: Remote Repository 페이지에서 새로고침하면 Push된 파일이 보임
Local Repository에 Pull하기
: Remote Repository의 내용에 맞춰 Local Repository를 갱신하려면 Git Pull 사용
-> Git Pull
git pull origin <branchname>
git pull origin master/main
git clone https://github.com/<respository>.git
git clone https://github.com/MJLOO/HelloGit.git
git clone https://<username>:<token>@github.com/<repository>.git
git branch
git branch -r
git branch -a
git branch <branchname>
git checkout <branchname>
git checkout -b <branchname>
git push origin <branchname>
git branch -d <branchname>
git push origin --delete <branchname>
<제로베이스 데이터 취업 스쿨>