Git 시작하기
본 내용은 Git 공식 매뉴얼(1.시작하기)을 바탕으로 작성되었습니다.
Git 설치
Git 사용 방법으로는 CLI(Command line interface)), GUI 두가지가 있다. CLI에서 Git 모든 기능 지원하기에 CLI기준으로 진행할 것이다.
Git 최초 설정
Git 설치 후, 사용 환경을 설정해주어야 한다.
아래의 설정들은 한 컴퓨터에서 한 번만 설정하면 되며, Git을 업그레이드해도 유지된다. 설정은 수정도 가능하다.
설정 명령어
config 명령어를 통해 설정 또는 확인, 변경 가능하다. 아래 내용은 명령어 실행 옵션
- git config를 통해 사용 방법 확인(명령어 Help)
$ git config
usage: git config [<options>]
Config file location
--global use global config file
--system use system config file
--local use repository config file
--worktree use per-worktree config file
-f, --file <file> use given config file
--blob <blob-id> read config from given blob object
Action
--get get value: name [value-regex]
--get-all get all values: key [value-regex]
--get-regexp get values for regexp: name-regex [value-regex]
--get-urlmatch get value specific for the URL: section[.var] URL
--replace-all replace all matching variables: name value [value_regex]
--add add a new variable: name value
--unset remove a variable: name [value-regex]
--unset-all remove all matches: name [value-regex]
--rename-section rename section: old-name new-name
--remove-section remove a section: name
-l, --list list all
-e, --edit open an editor
--get-color find the color configured: slot [default]
--get-colorbool find the color setting: slot [stdout-is-tty]
Type
-t, --type <> value is given this type
--bool value is "true" or "false"
--int value is decimal number
--bool-or-int value is --bool or --int
--path value is a path (file or directory name)
--expiry-date value is an expiry date
Other
-z, --null terminate values with NUL byte
--name-only show variable names only
--includes respect include directives on lookup
--show-origin show origin of config (file, standard input, blob, command line)
--default <value> with --get, use default value when missing entry
설정 파일
설정들은 설정 파일에 저장되는데 하나의 파일에 저장되어 있지 않다. 특성에 따라 3개 파일에 저장되며, 설정 파일의 위치 및 파일명, 특징은 아래와 같다. 각 설정의 우선 순위는 local > global > system (3 > 2 > 1) 이다.
- System - 시스템 설정 파일
- 시스템의 모든 사용자와 모든 저장소에 적용되는 설정
- 위치: C:/Program Files/Git/etc/gitconfig
- 위의 경로는 Git 설치 시, 지정한 경로 (C:/Program Files/Git)
- 시스템 설정 파일의 경로는 관리자 권한으로 -f 또는 --file 옵션을 사용하여 변경 가능
(참고: 실행해보았는나 변경 실패)
- $git config --system 으로 시스템 설정 확인, 변경 가능 (관리자 권한 필요)
$ git config --system <key>
$ git config --system <key> <value>
- Global - 사용자별 설정 파일
- 특정 사용자에게만 적용되는 설정
- 보통 사용자 임의 설정은 해당 파일에 저장되도록 --global 옵션 사용
- 위치: C:/Users/사용자계정/.gitconfig, C:/Users/사용자계정/.config/git/config
- $git config --global 로 확인, 변경 가능
$ git config --global <key>
$ git config --global <key> <value>
- Local - Repository(Project) 설정 파일
- 특정 저장소(혹은 현재 작업중인 프로젝트)에만 적용
- 위치: C:/Program Files/Git/.git/config
- --local 옵션으로 이 파일을 사용하도록 지정 가능
- 기본적으로 --local옵션이 적용되어 있음 (default)
- 이 옵션을 적용하려면 Git 저장소인 디렉토리로 이동 한 후 적용 가능
(참고: 현재 확인 못함/실행안됨: --local can only be used inside a git repository)
사용자 정보 설정
- 사용자 이름과 이메일 주소 설정
-
Git 설치 후, 가장 먼저 해야하는 설정
- Commit할 때마다 사용자 정보 사용히며, 한 번 Commit한 후에는 정보 변경 불가
(참고: Commit 전에는 변경 가능. commit후 확인 필요) - 공용PC이거나 프로젝트마다 다른 이름과 이메일 주소를 사용할 경우, --local 옵션으로
$ git config --global user.name 이름
$ git config --global user.email 이메일주소
$ git config --global user.name kakim0
$ git config --global user.email kakim0@email.com
편집기 설정
- Git에서 사용할 텍스트 편집기 설정
- 기본적으로는 시스템의 기본 편집기(nano) 사용
- 사용할 기본 편집기 변경 가능
- Unix - Emacs, Vim, gedit, …
$ git config --global core.editor 편집기명
- Windows - Notepad++ (실행파일의 전체 경로로 설정 (“C:/…”))
$ git config --global core.editor “전체 경로/파일명”
- Unix - Emacs, Vim, gedit, …
실행 예) 편집기 설정
$ git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -nosession"
## notepad++ 옵션
# -multiInst : Launch another Notepad++ instance
# nosession : Launch Notepadd++ without previous session
설정 확인
설정은 설정 파일에 “<key> = <value>“ 형태로 저장되어 있어, 모든 설정 또는 특정 설정 확인이 가능하다.
- config 명령어를 사용하여 설정 확인
- --list 또는 -l 옵션: 모든 설정 확인
$ git config --list
- <key>를 이용한 특정 설정 확인
$ git config
- --list 또는 -l 옵션: 모든 설정 확인
- Git Bash에서 cat이나 편집기로 설정 파일을 열어서도 확인 가능
(config 명령어를 통해 확인)
실행 예) 모든 설정확인
$ git config --list
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
core.autocrlf=true
core.fscache=true
core.symlinks=false
credential.helper=manager
user.name=kakim0
core.editor='C:/Program Files/Notepad++/notepad++.exe' -multiInst -nosession
실행 예) 특정 설정 - 사용자명 확인
$ git config user.name
kakim0
실행 예) Git bash에서 cat으로 설정 파일에 저장되어 있는 값 확인
$ cat .gitconfig
만약 설정 확인 결과가 이상하다면?
설정 확인 결과가 설정한 값과 다를 경우, 해당 설정(<key>값)이 여러 설정 파일에 각기 다르게 저장되어 있는 것일 수 있다. 설정 파일에서 말했듯이 설정 파일에 따라 우선 순위가 있는데, 이 때문에 발생한 문제일 수도 있다. 이땐, 설정 파일을 직접 확인해보면 된다.
어떤 파일에 저장된 설정값을 가져온 것인지 ”--show-origin” 옵션으로 확인할 수 있다.
$ git config --show-origin <key>
실행 예) 특정 설정 확인
$ git config --show-origin user.name
file:C:/Users/kim/.gitconfig kakim0
실행 예) 모든 설정 값 확인
$ git config --show-origin --list
file:C:/Program Files/Git/etc/gitconfig http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
file:C:/Program Files/Git/etc/gitconfig http.sslbackend=openssl
file:C:/Program Files/Git/etc/gitconfig diff.astextplain.textconv=astextplain
file:C:/Program Files/Git/etc/gitconfig core.autocrlf=true
file:C:/Program Files/Git/etc/gitconfig core.fscache=true
file:C:/Program Files/Git/etc/gitconfig core.symlinks=false
file:C:/Program Files/Git/etc/gitconfig credential.helper=manager
file:C:/Users/kim/.gitconfig user.name=kakim0
file:C:/Users/kim/.gitconfig core.editor='C:/Program Files/Notepad++/notepad++.exe' -multiInst -nosession
도움말
명령어에 대한 도움말이 필요할 때, help 명령어로 도움말을 볼 수 있다.
- 자세한 도움말 전체
- 오프라인으로 확인 가능
- “C:/Program Files/Git/mingw64/share/doc/git-doc”에 html 파일로 존재
$ git help 명령어
- 간단한 도움말
- 간단한 사용 방법, 옵션 확인
- 명령어의 -h 또는 --help 옵션 사용
$ git 명령어 -h
$ git 명령어 --help
Comments