[ 선행 과정 ]
[ Local ---> Remote repository 업로드용 저장공간]
git add test.txt # working drirectory ---> index(stage)
git status # 현재 상태 체크
git commit -m 'first commit' test.txt
# index(stage) ---> Head (-m은 메시지를 의미)
[ Local ---> Remote repository(=github) ]
git remote add origin https://<user.name>:<token>@github~.com
git remote -v
# ~~~(fetch), ~~~~(push) 두 가지가 출력되어야 정상적으로 업로드된 것임
git push origin master(또는 main) # Head ---> Git Hub
[ Remote 변경사항 ---> Local repository ]
git pull origin master
< 실습 예제 >
- Local Repository 생성
- 위치: git_ws 하위폴더 / 이름 : exam_project
cd Documents/git_ws
mkdir exam_project
cd exam_project
- 파일생성 후 Git으로 관리 시작
- 파일명 : exam.txt / index에 추가 / head에 등록
touch exam.txt # 파일생성
git init # git에서 관리 시작
git add exam.txt # working directory ---> stage
git commit -m 'add exam.txt' exam.txt # stage ---> head
- Remote Repository 생성
- 이름 : exam_project / 빈 프로젝트 상태
- Remote Repository에 등록
- 2번 예제에서 생성한 exam.txt 등록 후 확인 / token은 기존의 것 활용
git remote add origin https://<user.name>:<token>@~.com
git remote -v
~~~~~ (fetch)
~~~~~ (push)
- Local 변경내용 ---> Remote에 반영
- commit 항목을 remote repository에 반영
- remote repository에서 exam.txt 확인
git push origin master
- Remote 변경내용 ---> Local에 반영
git pull origin master
- commit 만들고 각각 Local, Remote에 반영
- 7-1. Local에서 exam2.txt. 생성 후 remote에 반영, 확인
touch exam2.txt
git add exam2.txt
git commit -m 'commit 1' exam2.txt
git push origin master
- 7-2. Remote에서 exam3.txt 수정 후 local에 반영, 확인
- This is commit exam
cat > exam3.txt
This is exam3. # enter키 + ctrl + D
cat > sample.py # ' > ' 있으면 파일 만들고, 그 안에 담길 내용 작성
print('sample 1') # enter키 + ctfl + D : 출력
cat sample.py
print('sample 1')
cat >> sample.py
print('sample 2')
cat sample.py
print('sample 1')
print('sample 2')