[git] local/remote repo

svenskpotatis·2023년 10월 6일
0

📌 add -> commit -> push

Local Repository

Local Repository는 Git이 관리하는 3가지 단계로 구성

  • Working Directory (작업공간) - 실제 소스 파일, 생성한 파일들이 존재
  • Index (Stage) - Staging area (준비영역) 의 역할, git add한 파일들이 존재
  • HEAD - 최종 확정본, git commit 한 파일들이 존재

[Working Direcroty] -add-> [Index(Stage)] -commit-> [HEAD]

  • git init
mkdir git_ws
cd git_ws
mkdir test_project
cd test_project

git init
  • ls -all: 숨긴 파일 보기
ls 
ls -all 
  • test.txt 만들기
touch test.txt
  • git status
git status
  • git add
git add fileName
git add test.txt
  • git commit
git commit -m 'first commit' test.txt

Remote Repository

  • git 사이트에서 test_project repository 생성

  • token 생성: settings -> developer settings -> new personal access token(classic)

  • Remote Repository 등록 with Username and Token

git remote add origin https://<username>:<token>@github.com/<repository>.git
  • Remote Repository 정보 확인
git remote -v
  • 연결 끊기
git remote remove origin

📖 Remote Repository에 변경내용 push 하기

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

git push origin <branchname>
test_project % git push origin master
test_project % git push origin main

Local Repository 에 pull 하기

Remote Repository의 내용에 맞춰 local repository를 갱신하려면 git pull 사용

git pull origin <branchname>
test_project % git pull origin master
  • ls 로 확인
  • cat exam2.txt: exam2.txt 내용 확인

0개의 댓글