Repository

eunbi kim·2024년 4월 11일
0
  • Local Repository 생성
  • Remote Repository 생성
  • Git Push & Pull
  • Default Branch
  • Remote repository 복제하기

Local Repository는 3가지 단계로 구성되어 있다.
Working Directory -> Index(Stage) -> HEAD
1. Working Directory: 실제 소스 파일, 생성한 파일들이 존재
2. Index(Stage): 준비 영역. git add한 파일들이 존재
3. HEAD: 최종 확정본, git commit한 파일들이 존재

  • Workspace 생성
mkdir git_ws
  • Working Directory 생성
    workspace로 이동한 뒤 test 디렉토리 생성하였다
cd git_ws
mkdir test_project
  • Git init
    폴더에서 git을 초기화하는 명령어를 사용하면 해당 폴더를 git이 관리하기 시작
    -> repository가 된다
git init
  • 파일 생성
    working directory에 파일을 생성. touch <- 빈 파일 생성 명령
touch test.txt
  • Git add
    working directory 에서 stage에 추가
git add test.txt
  • Git status
    git에 존재하는 파일 확인
git status

  • Git commit
    stage -> head에 반영 (확정)
    " 여기에 의미있는 설명 넣기 "
git commit -m 'first commit' test.txt


Remote repository 생성

Github 에서 생성한다~~

project 이름은 local에서 생성한 것과 동일하게 하고,
연습용이니 private로 설정하였다.

  • Github Token 생성
    remote 접속 시 비밀번호 대신 Token을 사용
    Settings -> Developter settings -> perosnal access tokens

Remote repository 등록

Token을 사용하여 local 에 연동할 remote repository를 등록하자

Github home -> 생성해둔 repository 선택 -> https 주소 복사

  • Remote repository 등록 (username, token 같이 등록하여 번거롭지 않게)
git remote add origin https://<username>:<token>@github.com/<repository>.git
  • Remote Repository 정보 확인
git remote -v

Git Push & Pull

Remote repository에 변경 내용 Push하기

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

  • Git Push
git push origin <branchname>

test_project라는 repository에 master branch를 push할 거야

push를 하면, local에서 커밋한 내용이 반영이 되어 있다.

Remote repository에 Pull하기

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

  • Git Pull

일단 remote가 바뀌어 있어야 하니까
ReadMe파일을 만들어주었고

다시 로컬로 가서
ReadMe 파일을 로컬로 pull하기!

git pull origin <branchname>

push와 똑같은 형식이다.

폴더에 생성됨을 확인할 수 있다.

Readme.md가 잘 추가되었다.


Default Branch

로컬에서 먼저 시작해서 remote에 올렸을 땐
default branch는 master였다.
반대로 remote에서 먼저 생성했을 땐 디폴트가 main으로 설정되었다.

기본 설정에서 branch명을 정하고 싶다: Settings -> Repositories -> Default branch에서 디폴트값을 설정해줄 수 있고,

그냥 수정하고 싶다: 처음 화면에서 branch -> view all branches -> rename branch

협업하는 사람들과 통일해야 하는 부분이다.

Remote repository 복제하기

누군가 만들어놓은 것을 처음 복제해서 사용하기 시작할 때!

Local repository를 생성하지 않은 상태에서
Git Clone 명령을 사용하여 Remote repository를 Local에 복제할 수 있다.

git clone https://github.com/<repository>.git

username과 token 사용하기

git clone https://<username>:<token>@github.com/<repository>.git

0개의 댓글