티스토리 뷰

Git 에 대한 초보자 이해법

 

1. Git 설치 및 설정

1-1 Git 설치

 

1-2 Git global 설정

git config --global user.name "sample"
git config --global user.email "sample@naver.com"
  • Git bash 또는 cmd 창에 입력
  • 최초 Git 설정으로 해당 PC 에서 Git 처음 실행 시 설정 필요
  • 사용할 Git Hub 의 연결된 username 과 useremail 등록
  • username 과 useremail 변경 시에도 동일하게 입력

1-3 Git global 설정 확인

git global --list

 

2. Git Hub 가입 후 Repository 생성

 

 

 

3. 내 PC 특정 폴더에 Repository 생성

* Git Hub 의 Repository 에 Push 또는 Pull 하기 위해서 내 PC 특정 폴더에 Repository 생성 필요

 

 

  • 개발중인 Code 를 비어있는 Git Hub Repository 에 Push 하려면 개발중이 Code 가 있는 폴더에서
  • Git Hub Repository 에 이미 개발중인 Code 를 내 PC 로 Pull 하려면 해당 코드를 받고 싶은 폴더에서
  • 마우스 우클릭
  • Git Bash Here 클릭

 

git init

git init 명령어 입력 시 해당 폴더에 Repository 가 생성 되며 master branch 가 생성됨

 

4. Remote 등록

 

Git Hub Repository 주소

 

git remote add origin https://github.com/*****/testRepository.git

* 위 명령어 옵션 설명

  remote add : remote 추가하는 명령어

  origin : 추가하고 있는 remote 의 이름

  https://github.com/*****/testRepository.git : 추가하고자 하는 Git Hub 의 Repository 주소 

 

5. Push 또는 Pull

5-1 개발중인 Code 를 비어있는 Git Hub Repository 에 Push

 

 

 

1) git add

 

git add '파일명.확장자'

특정 파일 추가하기

 

또는

git add .

해당 폴더 전체 파일 추가

 

2) commit

 

git commit -m 'commit 시 메모쓰기'

 

3) push

 

git push origin master

* 위 명령어 옵션 설명

  push : push 하는 명령어

  origin : push 하고자하는 remote 의 이름

  master : push 하고자하는 branch 이름

 

또는

 git push --set-upstream origin master

* 위 명령어 옵션 설명

  push : push 하는 명령어

  --set-upstream : push 에 특정 reomte 지정하는 명령어 

  origin : push 하고자하는 remote 의 이름

  master : push 하고자하는 branch 이름

 

즉, 이 명령어 이후 push 시 origin master 생략하고 'git push' 만으로도 push 가능

 

5-2. Git Hub Repository 에 이미 개발중인 Code 를 내 PC 로 Pull 

 

 

1) pull

 

git pull origin master

* 위 명령어 옵션 설명

  pull : pull 하는 명령어

  origin : pull 받고자하는 remote 의 이름

  master : pull 받고자하는 branch 이름

 

6. clone

git clone https://github.com/*****/testRepository.git

 

6-1 clone 과 pull 의 차이

clone 명령어

: 내 PC 에 Repositroy 생성 없이, romote 등록 없이 해당 Git Hub Repository 주소에 있는 코드를 단순히 내려받는 명령어

 

pull 명령어

: Git Hub Repository 에 있는 코드를 내 PC 로 업데이트 하는 명령어

 즉, 이미 작업중인 내 PC Repositroy 에 있는 코드에 업데이트 된 Git Hub Repository 에 있는 코드를 업데이트 하는 명령어

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함