본문 바로가기
Git

[Git] git 이용 방법 - repository 생성, local 저장소에 연결, pull & push

by Gina Sim 2020. 11. 24.

1. GitHub에 Repository 생성

(1) GitHub 접속, 로그인
(2) 우측 상단 프로필 클릭(검은 화면에 작은 동그라미) -> "your repositories"
(3) Repositories 목록 화면에 우측 상단 "New"

 

"New" 클릭하면 다음과 같은  repository 생성 화면 나옴
(4) Repository name 입력
(5) Description과 "Initialize this repository with:"는 옵션 
(6) 다 적고 나면 하단 "create repository" 클릭
(7) 생성 완료!!

컴퓨터에 pull 해보기 위해 readme를 바로 만들면서 시작

 


2. local 저장소 생성하고 연결

(1) 원하는 위치에 폴더 생성
(2) 폴더 우클릭 -> "Git Bash Here"

바탕화면에 test 폴더 생성 후 git 연결

 

"Git Bash Here"하면 다음과 같은 창이 뜸
더보기

핵심만 빠르게 알고 싶으신 분들을 위해

다음의 순서로 입력

1. git init

(2. git status)

3. git remote add origin http://...... 

   (http://...... 위치에 연결하고자 하는 repository의 주소 넣어줌)

4. git pull origin main 

 

working directory에서 작업

 

5. git add --all

6. git commit -m "commit에 대한 설명"

(7. git branch -M main)

5. git push origin main

 

 

 

(1) "git init"  -> 해당 폴더를 local git 저장소로 등록해줌
(2) "git status"  -> git project 상태 확인

git init한 폴더 = working directory
현재 test 폴더에 아무 파일도 없기 때문에 "nothing to commit"이라고 뜸

 

(3) "git remote add origin 원격 저장소 주소"  -> 입력한 원격저장소를 origin이라는 이름으로 연결

origin은 불러운 원격 저장소 주소를 가리키는 역할 ->
pull과 push를 할 때 주소 입력 대신 origin을 통해 수행

 

더보기

연결할 repository 페이지의 우측 상단 "code"를 클릭하면 주소 복사 가능
HTTPS 형태로 주소 옆쪽의 버튼 클릭하면 주소 복사됨

 

 


3. 원격 저장소에 있는 파일들을 local 저장소로 불러오기

(4) "git pull origin main"

"origin의 main branch에서 (pull) 불러오겠다."
즉, origin이 가리키는 원격 저장소 주소의 main branch에서 모든 파일 및 폴더를 불러옴

"git pull origin main"후 test 폴더에 README가 생긴 것 확인

 


4. working directory에서 작업 & local 저장소에서 원격 저장소로 변경된 파일/ 폴더 내보내기

new.md라는 파일 만들고 test 폴더에 저장

 

(5) "git add --all" 
(6) "git commit -m "commit에 대한 설명"  
(6) "git branch -M main"   -> 기본으로 master로 설정되어 있는 Git의 branch를 main으로 변경
(7) "git push origin main"   -> 원격 저장소에 local 저장소의 파일/ 폴더 업로드(push)
더보기

Git 구조

출처:  https://victorydntmd.tistory.com/73

 

"git add --all" 

   -> working directory에서 수정된 파일/폴더들을 indexing

   -> 즉, working directory의 파일들을 staging area로 올림


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

   -> indexing 된 파일들을 local 저장소에 등록하면서 working directory내에서 변경된 파일/ 폴더를 기록

   -> 즉, staging area에 add 한 파일/폴더의 변경사항들을 local repository에 기록/ 저장

 

git의 branch가 (master) -> (main)으로 변경 됨

 

 

"git push origin main"후 GitHub repository에 new.md 파일이 업로드 됨

 

 

 

 

반응형

댓글