Git 명령어

[GIT] 자주 사용하는 Git 명령어 모음

1. git init

Git 저장소 생성. 실행시 저장소 구성을 위한 .git 폴더가 생성된다.

2. git remote add [별칭][원격지 주소]

$ git remote add origin https://github.com/jcwooo/ggb

‘origin’은 원격 저장소를 가르키는 별칭이다.

    2-1. git remote -v

   현재 연결되어 있는 원격 repository 확인.

    2-2. git remote remove origin

   원격 repository 연결 끊기.

3. git status

현재 저장소 파일들의 상태를 확인한다. 파일을 수정하였다면 위 명령으로 확인할 수 있다.

$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
        modified:   src/html.js

src/html.js 파일이 수정되었음을 확인할 수 있다.

4. git add

git status로 수정 파일을 저장소로 반영하기 위해선 인덱스에 파일을 추가해야한다. Git Repository 구조는 ‘작업폴더(Working Directory) > 인덱스(Staging Area) > 저장소(Head Repository)로 구성된다.
git add 명령은 저장소에 commit 하기 위해 추가 및 수정 파일을 인덱스에 기록한다.

$ git add src/html.js

5. git commit -m [설명]

인덱스(Staging Area)에 올린 변경사항을 Head에 적용한다.

$ git commit -m "html 변경"

6. git push origin master

변경 내용을 원격 저장소로 보낸다.

$ git push origin master

7. git clone [url]

git 저장소를 복사한다.

$ git clone https://github.com/jcwooo/source

source 디렉토리를 생성하고 저장소의 데이터를 모두 복사한다.
디렉토리 명을 변경하고 싶으면 아래와 같이 clone해주면 된다.
아래 명령어 실행시 ‘new-name’이란 디렉토리 하위에 데이터가 복사 된다.

$ git clone https://github.com/jcwooo/source new-name

8. git branch [branch name]

branch를 생성한다. 아래 코드 실행시 ‘branch1’이란 branch가 생성 된다.

$ git branch branch1

    8-1. git checkout -b [branch name]

   branch 생성 후 이동.

$ git checkout -b [branch1]

    8-2. branch 수정 파일 git에 커밋

$ git add [file name]
$ git commit -m "commit message"
$ git push origin [branch name]

    8-3. branch 병합

$ git checkout master // 1. master로 전환
$ git merge [branch name]		

    8-4. branch 삭제

$ git branch -d [branch name]

MyResume
고구장의 개발 메모, 기록, 공유 하고픈 정보를 위한 블로그입니다.

GitHubinstagram