- Local Repository 생성
(C:\Users\hjh\Documents\git_ws\test_project)- 거기에 파일 생성
- 그 파일을 Working Directory에서 Stage 영역으로 파일 add
- 그 파일을 Stage 영역에서 HEAD 영역으로 파일 commit
- Local Repository와 같은 이름의 비어있는 Remote Repository 생성
- Remote Repository에 접근하는 용도로 Token 생성
- Local Repository에 연동할 Remote Repository 를 등록(연결)
- Local Repository에 있는 걸 Remote Repository에 Push
- Remote Repository에 있는 걸 Local Repository으로 Pull
• Working Directory (작업공간) - 실제 소스 파일, 생성한 파일들이 존재(우리가 보는 파일, git이 관리하진 않음)
• Index (Stage) - Staging area (준비영역) 의 역할, git add 한 파일들이 존재(add 하는 순간 git에 등록되고, 관리시작)
• HEAD - 최종 확정본, git commit 한 파일들이 존재
(버전이 매겨짐)
git_ws
: Repository 이 모여있는 최상위 폴더% mkdir git_ws
-> 터미널에서 작성
% cd git_ws
git_ws % mkdir test_project
git init
폴더에서 Git 을 초기화하는 명령어를 사용하면 해당 폴더를 Git 이 관리하기 시작
test_project로 이동을 해서 폴더 안에서 git init 을 하는 순간 그 폴더는 Repository가 된다.
-> Git 이 폴더를 Working Directory로 인식하고 관리하기 시작한다라는 뜻
git_ws % cd test_project
test_project % git init
Initialized empty Git repository in /Users/nomaefg/.../git_ws/.git/
-> git이 관리하는 Working Directory가 나온다
test_project % touch test.txt
test_project % ls
test.txt
git status
test_project % git status
On branch master # 넌 지금 On branch master(main)에 있다
No commits yet # 아직 commit은 없다
Untracked files: # add 해야 할 파일이 있다
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit
but untracked files present (use "git add" to track)
-> use "git add <file>..." to include in what will be committed
이 부분을 참고하자
git add <filename>
Index (stage) 에 추가된 변경사항을 HEAD 에 반영 (확정)
Commit을 함으로써 3단계 영역(HEAD)으로 들어옴
git commit -m "commit 에 대한 설명" <filename>
git remote add origin https://github.com/<repository>.git
-> 이렇게 하면 id, pw를 Remote와 연동할때마다 입력안해도 됨
# 원래 한 줄인데 길어서 두줄로 함
# 주소값 안에 <username>:<token>@ 가 추가됨
git remote add origin https://<username>:<token>@
github.com/<repository>.git
# username : zero
# token : ghp_Ko 이라면(실제로는 길다)
git remote add origin https://zero:ghp_Ko@github.com~~
# 이렇게 넣어준다
예시
test_project % git remote add origin
https://zerobasegit:ghp_yazM0qurHSashbS7wVeQcBFEJ
2QPRX3Mgzus@github.com/zerobasegit/test_project.git
git remote -v
test_project % git remote -v
2origin https://zerobasegit:...Mgzus@github.com/zerobasegit/test_project.git (fetch)
3origin https://zerobasegit:...Mgzus@github.com/zerobasegit/test_project.git (push)
git push origin <branchname>
예시
test_project % git push origin master
git pull origin <branchname>
• 위치 : git_ws 폴더 하위
• 이름 : exam_project
• 파일 : exam.txt
>>touch exam
• Index 추가 (git add를 의미)
>> git add exam.txt
• HEAD 등록 (git commit을 의미)
>> git commit -m 'add exam.txt' exam.txt
• 이름 : exam_project
• 빈 프로젝트
• exam_project 의 Local Repository 에 앞서 생성한 remote repository 등록 후 확인
• token 은 앞서 수업에서 생성한 token 계속 사용
• commit 항목을 Remote Repository 에 반영 (push)
• Remote Repository 에서 exam.txt 확인
exam.txt 파일 수정 : This is git exam.
Local Repository 에 반영 후 내용 확인
• Commit 1 :
Local Repository 에서 exam2.txt 생성 후 Remote Repository 에 반영, 확인
• Commit 2 :
Remote Repository 에서 exam2.txt 수정 후 Local Repository 에 반영, 확인 - This is git exam2.
• Commit 3 :
Local Repository 에서 exam3.txt 생성 후 Remote Repository 에 반영, 확인 - This is git exam3.
• Commit 4 :
Remote Repository 에서 exam3.txt 수정 후 Local Repository 에 반영, 확인 - This is commit exam.
cat > exam3.txt
This is exam3.
# 위까지 기재하고 Ctrl + d 눌러주면 됨
# 생성하면서 바로 내용입력됨