Git (3)_Local Repository / cat

Jio.B·2023년 7월 29일
0

(ZB) DS 16기_part06_Git

목록 보기
3/9

[ 선행 과정 ]

  1. git bash에 github 계정 등록
  • git config <user.name>
  • got config <user.email>
  1. Loacal Repository(github 전용 work space 폴더) 생성
  2. 테스트용 빈 파일(text.txt) 생성
  3. master 폴더 지정
  4. Remote Repository(github 웹에서 project 파일) 생성

[ 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


< 실습 예제 >

  1. Local Repository 생성
  • 위치: git_ws 하위폴더 / 이름 : exam_project
cd Documents/git_ws
mkdir exam_project
cd exam_project
  1. 파일생성 후 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
  1. Remote Repository 생성
  • 이름 : exam_project / 빈 프로젝트 상태
  1. Remote Repository에 등록
  • 2번 예제에서 생성한 exam.txt 등록 후 확인 / token은 기존의 것 활용
git remote add origin https://<user.name>:<token>@~.com
  
git remote -v
  ~~~~~ (fetch)
  ~~~~~ (push)
  1. Local 변경내용 ---> Remote에 반영
  • commit 항목을 remote repository에 반영
  • remote repository에서 exam.txt 확인
git push origin master
  1. Remote 변경내용 ---> Local에 반영
git pull origin master
  1. 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

  • (기존 내용이 있다면) 새로 작성한 내용으로 덮어씌우기
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')

0개의 댓글

관련 채용 정보