Git

From 탱이의 잡동사니
Jump to navigation Jump to search

Overview

Git 사용법 정리.

Basic

Branching

branching model

git에서의 브랜치 사용은, 단순한 명령어를 사용할 줄 아는 것보다 어떤 구조로 브랜치가 뻗어나가고, 통합되는지를 아는 것이 더 중요하다. 자동으로 생성되는 master branch 에는 Tag 와 같이 배포된 버전만을 관리하도록 한다. 그리고, develop branch 에는 현재 진행중인 모든 변경사항들이 적용될 수 있도록 한다. 그리고, 새로운 기능을 개발해야 하는 상황이라면 develop branch에서 새로운 branch 를 파생하여 개발하도록 한다(이건 약간 다를 수있다). hotfix 의 경우, master branch 에서 파생하여 수정 후, 바로 적용할 수 있도록 한다.

새로운 기능을 위한 branch 를 생성할 때, 두 가지 방식을 사용할 수 있다. 하나는 master branch 에서 파생하는 방법이고, 다른 하나는 develop branch 에서 파생하는 방법이다. develop branch 에서 파생할 경우에는 현재 적용을 위해 테스트 중인 모든 기능과의 호환성을 함께 테스트할 수 있지만 그만큼 현재 배포중인 버전과의 차이가 많이 난다는 문제가 있다. 하지만, master branch에서 파생하는 경우는, 정 반대의 문제가 발생하게 된다.

여기서 중요한 점은, branching 을 하는 과정에서는 어떠한 정해진 룰이 없다는 것이다. 그냥 각기 상황에 맞는 방식을 적용하여 사용하면 된다.

branch

branch 를 생성/삭제/변경 한다. <source lang=bash> $ git branch [--color[=<when>] | --no-color] [-r | -a] [--list] [-v [--abbrev=<length> | --no-abbrev]] [--column[=<options>] | --no-column] [(--merged | --no-merged | --contains) [<commit>]] [<pattern>...] $ git branch [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>] $ git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>] $ git branch --unset-upstream [<branchname>] $ git branch (-m | -M) [<oldbranch>] <newbranch> $ git branch (-d | -D) [-r] <branchname>... $ git branch --edit-description [<branchname>] </source>

checkout

브랜치 생성과 동시에 checkout 까지 동시에 한다. <source lang=bash> $ git checkout -b feature_1212 Switched to a new branch 'feature_1212' </source>

clone

-b, --branch

clone 시 특정 브랜치를 지정하여 clone 할 때 사용하는 옵션이다.

$ git clone -b <branch> <remote_repo>

Example
$ git clone -b my-branch git@github.com:user/myproject.git

Alternative (no public key setup needed):
$ git clone -b my-branch https://git@github.com/username/myproject.git

With Git 1.7.10 and later, add --single-branch to prevent fetching of all branches. Example, with OpenCV 2.4 branch:
$ git clone -b 2.4 --single-branch https://github.com/Itseez/opencv.git opencv-2.4

pull

pull all branches

$ git pull --all

commit

--amend

기존의 commit 에 내용 수정하기

$ git commit --amend

config

git 환경변수 값을들 설정/변경/삭제 한다.

$ git config [options]

--global

global config file 을 사용한다.

$ git config --global core.editor "vim"

See also

References

<references />