데이터 취업 스쿨 스터디 노트 -(36) Git 로컬, 리모트 레퍼지토리 push/pull

테리·2024년 7월 29일
0

Local Repository

Local Repository 생성

폴더 생성 mkdir

Git init

git init을 하면 해당 폴더가 워킹 레퍼지토리가 됨.

파일 생성 add

  • Working Directory 에 파일을 생성
  • touch 파일명.확장자

Git Status

Git에 존재하는 파일 확인

git status

Git Add

Working Directory 에서 변경된 파일을 Index (stage)에 추가

git add 파일명.확장자

Git Commit (버전을 매기는 것)

Index (stage) 에 추가된 변경사항을 HEAD 에 반영 (확정)

Remote Repository

Remote Repository 생성

  • github에서 생성함
  • create Repository 클릭

Github Token 생성

보안상의 이유로 Remote Repository 접속 시 비밀번호 대신 Token 을 사용

사용자 메뉴에서 Settings 선택 -> Developer settings 선택 -> Personal access tokens 선택 -> Generate new token 선택 -> Token 이름 입력 + No expiration 을 선택 + repo 선택 > Generate token 버튼 선택

Remote Repository 등록

Local Repository 에 연동할 Remote Repository 를 등록 (Token 사용)

Local Repository 에 Remote Repository 등록

  • Remote Repository 등록(이렇게 하면 아이디와 비번을 remote와 연동 할 때 마다 입력해줘야함.)
git remote add origin https://github.com/<repository>.git
  • Remote Repository 등록 with Username and Token(이렇게 하면 매번 입력하지 않아도 됨.)
git remote add origin https://<username>:<token>@github.com/<repository>.git

Remote Repository 정보 확인

git remote -v

Remote Repository 에 변경내용 Push 하기

Local Repository (HEAD) 에 반영된 변경내용을 Remote Repository 에도 반영하기 위해서는 Git Push 를 사용

commit으로 버전을 매기고 다 완료한 작업을 다른 사람들이 다 볼 수 있도록 push 하는 것임.

Git push

git push origin <branchname>


만약 master가 에러가 나면 main으로 하면 됨.

Local Repository 에 Pull 하기

Remote Repository 의 내용에 맞춰 Local Repository 를 갱신하려면 Git Pull 사용

git pull을 해야 원격 저장소에 있는 정보를 로컬로 가져와 동기화 할 수 있음!!! 그 다음에 git add, git commit, git push 작업을 해야함.

Git pull

git pull origin <branchname>

연습문제

파일을 만들 때 특정 텍스트도 같이 포함해서 만들려면
cat > 파일명 (엔터)
원하는 텍스트 (엔터)
ctrl + d

0개의 댓글