본문 바로가기
Server/git

[git] 깃기본 명령어

by 꼬바리 2021. 3. 26.
Git 깃의 기본 명령어를 알아보자.

 

 

참고 : http://unikys.tistory.com/323

Git 명령어를 입력할 수 있는 Git Bash를 실행해서 'git'을 실행해 보자.

 

 

요로코롬 나온다면 Git을 잘 설치한게 맞다.

 

 

 

'git'을 실행하면 기본적 명령어 목록이 친절히 나온다.

 

[ ] 안에 있는 파라미터와, 명령어 <command> 2가지로 나눌 수 있다.

 

 

 

[파라미터 형]

- 기본적인 설명을 보거나 설정을 할 수 있는 명령어

- 사용 방법 예 : git --version

 

 

파라미터 명 

설명 

 

 [--version]

 git 버전을 보여준다

git --version 

 [--help]

 git 기본 도움말을 표시한다

git --help 

 [-c name=value]

 커맨드 라인을 통해서 config 값을 설정하여 보낸다, config에서 설정하는 것과 같은 값을 name으로 가진다

 

 [--exec-path[=<path>]]

 실행 경로를 보여주거나 설정한다

git --exec-path

git --exec-path=c:/git/bin 

 [--html-path]

 브라우져 기반 도움말 위치를 보여준다

git -- html-path 

 [--man-path]

 man 명령어 기반 도움말 위치를 보여준다

git --man-path 

 [--info-path]

 정보 파일들이 저장된 위치를 보여준다

git --info-path 

 [-p|--paginate|--no-pager]

 화면에 표시되는 결과를 "less" 명령을 통해서 내보내거나 설정하지 않는다(--no-pager)

git --paginate commit 

 [--no-replace-objects]

 git 객체를 교체할 때에 교체 레퍼런스를 남기지 않는다

git --no-replace-objects cat-file commit foo

 [--bare]

 저장소를 빈 저장소로 취급한다. GIT_DIR이 설정되어있지 않으면 현재 디렉토리를 설정한다

git --bare 

 [--git-dir=<path>]

 저장소에 해당 경로를 추가하여 설정한다. GIT_DIR의 환경변수를 설정하는 것과 같다

git --git-dir=c:/bin

 [--work-tree=<path>]

 작업중인 트리에 해당 경로를 설정한다. GIT_WORK_TREE의 환경변수를 설정하는 것과 같다

git --work-tree=c:/bin

 [--namespace=<name>]

 Git의 네임스페이스를 설정한다. GIT_NAMESPACE의 환경변수를 설정하는 것과 같다

git --namespace=foo 

 <command>

 git 명령어

git commit 

 [<args>]

 git 명령어에 따른 아규먼트

git commit foo -f 

 

 

 

 

<명령어 Command>


: Git을 실질적으로 행동들을 제어하는 명령어

파라미터 명 

 설명

 

 add

 인덱스에 파일을 추가한다

git add doc/*.txt 

 bisect

 버그를 만들어낸 변화를 이진 탐색으로 검색한다

git bisect start

git bisect bad

git bisect good v2.6.13-rc2

git bisect visualize

git bisect view --stat

 branch

 branch를 조회, 생성, 삭제한다

git branch my2.6.14 v2.6.14

git branch -d my2.6.14

 checkout

 현재 작업중인 브렌치를 인덱스와 일치하도록 원복시킨다

git checkout master

git checkout hello.c

 clone

 해당 저장소를 복사해서 새로운 디렉토리에 저장소를 생성한다

git clone git://unikys.github.com

 commit

 저장소에 변화를 적용한다

git commit

git commit -a

 diff

 commit으로 인한 변화들과 현재 작업하는 branch와의 차이를 보여준다

git diff

git diff HEAD

 fetch

 다른 저장소로부터 파일들과 레퍼런스들을 다운 받는다

git fetch origin

 grep

 패턴과 일치하는 라인을 출력한다

git grep  'time_t' -- '*.[ch]'

 init

 빈 git 저장소를 생성하거나 git 저장소를 초기화시킨다

git init 

 log

 commit한 로그를 표시한다

git log

git log -3

git log --since="2 weeks ago" -- hello.c

 merge

 2개 이상의 개발 히스토리를 합친다

git merge origin

git merge --no-commit origingit merge fixes_branch patch_branch 

 mv

 파일이나 디렉토리를 이동하거나 이름을 바꾼다

git mv  hello.c new_hello.c

 pull

 fetch와 merge를 로컬이나 원격의 branch에 실시한다

git pull

git pull origin

 push

 원격의 레퍼런스를 업데이트ㅣ한다

git push public

git push origin

git push origin master

 rebase

 로컬 commit들을 자동으로 head로 업데이트하도록 설정한다

git rebase master

git rebase master myBranch

 reset

 현재 head를 특정 상태로 재설정한다

git reset

git reset --soft HEAD^

git reset --merge ORIG_HEAD

git reset -- hello.c

 rm

 현재 브렌치와 인덱스에서 파일을 삭제한다

 git rm doc/\*.txt

 show

 다양한 객체들을 보여준다

git show v1.0.0

git show master:Makefile

 status

 현재 작업중인 branch의 상태를 보여준다

git status 

 tag

 GPG(GnuPG)로 객체에 태그를 생성/조회/삭제/검증을 한다

git tag -a new_tag

 

 

: git에서 가장 많이 사용하는 명령어는 'commit', 'push', 'pull', 'add', 'diff', 'init', 'clone' 등이다.

728x90
반응형

댓글