▷ 오늘 학습 계획: Git 강의(3~4)
Working Directory(작업공간): 실제 소스 파일, 생성한 파일들이 존재
Index(Stage): Staging area(준비), git add 한 파일들이 존재
HEAD: 최종 확정본, git commit 한 파일들이 존재
Workspace 생성
mkdir git_ws
Workspace 로 이동한 뒤 Working Directory 생성
cd git_ws mkdir test_project
해당 폴더를 Git 이 관리하기 시작
- 생성한 폴더로 이동하여 Git init 을 실행하면 Repository 가 생성됨
git init
.git 폴더 확인하기
ls -all # 전체 목록 확인 # .git 으로 이동 후 Git 관련 파일들이 생성된 것을 확인 cd .git ls -all
touch 명령어: 빈 파일 생성
touch test.txt
Git 에 존재하는 파일 확인
git status
Local Repository 생성
- Git Add: Working Directory 에서 변경된 파일을 Index (stage)에 추가
- Git Commit: Index (stage) 에 추가된 변경사항을 HEAD 에 반영 (확정)
git add <filename> git commit -m "commit에 대한 설명" <filename>
Remote Repository 생성
- GitHub → Create Repository
- 토큰 등록: Settings → Developer settings → Personal access tokens → Generate new token
Remote Repository 등록
git remote add origin https://<username>:<token>@github.com/<username>/<repository>.git
- Remote Repository 정보 확인
git remote -v
Remote Repository에 변경 내용 반영하기: Push
# branchname은 초기에 master 또는 main으로 지정됨 git push origin <branchname>
Remote Repository의 변경 내용 가져오기: Pull
git pull origin <branchname>
문제
git_ws 폴더 하위에 exam_project 이름으로 Local Repository 생성
cd Documents/git_ws mkdir exam_project
exam.txt 파일 생성 후 Git으로 관리 시작 → Index 추가 → HEAD 등록
cd exam_project touch exam.txt ls git init git add exam.txt #Index 추가 git status git commit -m "add exam.txt" exam.txt #HEAD 등록 git status
exam_project 이름, 빈 프로젝트로 Remote Repository 생성
→ GitHub 홈페이지에서 만들기exam_project의 Local Repository에 Remote Repository 등록
git remote add origin https://<username>:<token>@github.com/<username>/<repository.git git remote -v
Local Repository 변경 내용을 Remote Repository에 반영
git status git push origin master
Remote Repository 변경 내용을 Local Repository에 반영
ls cat exam.txt git pull origin master
# 반영된 내용 확인하기 ls cat exam.txt git status git push origin master
참고) .gitignore
Git 버전 관리에서 제외할 파일목록을 지정하는 파일
사용자가 원하지 않는 파일들을 자동으로 commit 대상에서 제외
main 또는 master로 설정 되는데 수정 가능하다.
Default Branch 이름 설정값을 바꿀 수 있다.(Settings)
Local Repository 를 생성하지 않은 상태에서 Git Clone 명령을 사용하여 Remote Repository 를 Local 에 복제
git clone https://<username>:<token>@github.com/<username>/<repository>.git
Branch 조회
git branch #local git branch -r #remote git branch -a
Branch 생성
git branch <branchname> #local git push origin <branchname> #local → remote
Branch 이동
git checkout <branchname>
Branch 생성 및 이동
git checkout -b <branchname>
Branch 삭제
git branch -d <branchname> #local git push origin --delete <branchname> #local → remote
▷ 내일 학습 계획: Git 강의(5~6)