2. Local Repository

dorongpark·2022년 11월 19일
0

Git

목록 보기
3/7

Local Repository

  • 컴퓨터에서 작업하는 git에서 관리 하는 저장소
  • 구성(3단계)
    working directory (작업공간) : 실제 소스 파일 ,생성한 파일들이 존재
    - index(stage) : Staging area(준비 영역)의 역할, git add 한 파일들이 존재
    - HEAD : 최종 확정본, git commit한 파일들이 존재

Local Repository 생성

  1. Workspace 생성

git bash cmd

mkdir workspace_name
(참고로 mkdir은 make directory의 줄임말이다)

  1. Workspace로 이동 한 후 working directory 생성

cd workspace_name
mkdir test_project

  1. Git init

폴더에서 Git을 초기화 하는 명령어를 사용하면 해당 폴더를 Git이 관리하기 시작
즉, test_project에 있는 파일들은 git의 관리를 받음

git init

  1. 파일 생성

touch test.txt (test.txt 파일을 test_project 폴더 안에 생성)
ls (list의 줄임말로 test_project 안의 파일들을 보여준다)

  1. Git status

Git 에 존재하는 파일 확인

git status

  1. Git add

working directory에서 변경 된 파일을 index(stage)에 추가

git add file_name

  1. Git Comiit

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

git commit -m "commit에 대한 설명" file_name

  • -m : message이며 뒤에 commit에 대한 내용을 메세지로 취급
  • 최대한 잘 알아볼 수 있도록 메세지를 적어주는 것이 좋다


Remote repository 생성

  1. git hub를 통해 remote repository를 생성할 수 있다

  2. github Token 생성

얼마전부터 보안상의 이유로 remote repository 접속 시 비밀번호 대신 token 사용

github>settings>developer settings>personal access tokens 창을 통해 토큰을 발행할 수 있으며 생성 후에는 token 값이 보이지 않으므로 반드시 잘 복사해 두고 사용 해야 한다


local repository에 연동할 remote repository를 등록

  1. test_project의 코드 값과 토큰 값을 준비한다

  2. local repository에 remote repository 등록

git remote add origin http://username:token@~ 이후 주소

  1. remote repository 의 정보 확인

git remote -v

remote repository에 변경 내용 push 하기

  1. local reposit에 반영된 내용을 remote reposit에 반영하기 위해서는 git push 명령어를 사용

git push origin branch_name

  1. git hub에서 push된 내용 확인 하기

local repository에 pull 하기

  1. remote reposit의 내용에 맞춰 local reposit을 갱신하려면 git pull 사용

git pull origin branch_name

  1. remote로 부터 pull 된 파일 확인 하기

ls

profile
야 너도 분석 할수 있어

0개의 댓글