Linux에서 Git 설치 및 기본 설정 방법

Git 설치 방법 (CentOS 7.6 기준)

시스템에 Git를 설치하는 두 가지 주요 방법을 소개합니다: 패키지 매니저 사용과 소스 컴파일 설치.

1. 패키지 매니저를 통한 설치 (dnf)

[root@VM-0-17-centos ~]# dnf -y install git-all

이 명령어는 시스템 전체의 Git 관련 패키지를 포함하여 설치합니다. 가장 간편하고 신뢰할 수 있는 방법입니다.

2. 소스 코드로 직접 컴파일 설치

최신 버전이나 특정 옵션을 적용하고 싶은 경우, 소스에서 빌드하는 것이 적합합니다.

필수 의존성 패키지 설치

[root@VM-0-17-centos ~]# dnf -y install dh-autoreconf curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel
# 문서 형식 지원 추가 (doc, html, info)
[root@VM-0-17-centos ~]# dnf -y install asciidoc xmlto docbook2X

소스 압축 해제 및 구성

[root@VM-0-17-centos ~]# tar xvf git-2.9.5.tar.xz
[root@VM-0-17-centos ~]# cd git-2.9.5/
[root@VM-0-17-centos git-2.9.5]# make configure
[root@VM-0-17-centos git-2.9.5]# ./configure --prefix=/usr

빌드 과정에서 다음과 같은 오류가 발생할 수 있습니다:

/bin/sh: line 1: docbook2x-texi: command not found

해당 오류는 docbook2X 패키지가 존재하지만 실행 파일 이름이 맞지 않기 때문입니다. 이를 해결하기 위해 심볼릭 링크를 생성합니다:

[root@VM-0-17-centos git-2.9.5]# ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi

빌드 및 설치 완료

[root@VM-0-17-centos git-2.9.5]# make all doc info
[root@VM-0-17-centos git-2.9.5]# make install install-doc install-html install-info

성공적으로 설치되었는지 확인하려면 다음 명령어를 실행하세요:

[root@VM-0-17-centos ~]# git --version
git version 2.9.5

기본 설정

Git는 모든 커밋에 사용자 정보를 포함하기 때문에 초기 설정이 중요합니다.

사용자 정보 설정

[root@VM-0-17-centos ~]# git config --global user.name "John Doe"
[root@VM-0-17-centos ~]# git config --global user.email johndoe@example.com

--global 옵션은 시스템 전체에 적용되며, 한 번만 실행하면 됩니다. 프로젝트별로 다른 정보를 사용하고 싶다면 해당 프로젝트 디렉터리에서 --local 옵션으로 설정 가능합니다.

기본 텍스트 에디터 지정

[root@VM-0-17-centos ~]# git config --global core.editor emacs

커밋 메시지 작성 등에서 사용되는 기본 편집기입니다. 시스템 기본값은 vi 또는 vim입니다.

설정 정보 확인

[root@VM-0-17-centos ~]# git config --list
user.name=John Doe
user.email=johndoe@example.com

[root@VM-0-17-centos ~]# git config user.name
John Doe

[root@VM-0-17-centos ~]# git config --show-origin user.name
file:/root/.gitconfig	John Doe

--show-origin 옵션은 설정 값이 어디서 로드되었는지 알려줍니다. 여러 위치에서 동일한 설정이 중복될 수 있으므로 이 정보는 디버깅에 유용합니다.

Git 설정 파일의 계층 구조

Git 설정은 세 가지 레벨에서 관리됩니다:

  • 시스템 수준: /etc/gitconfig — 모든 사용자에게 공통된 설정. --system 옵션으로 접근.
  • 사용자 수준: ~/.gitconfig 또는 ~/.config/git/config — 현재 사용자 전용 설정. --global로 조작.
  • 프로젝트 수준: .git/config — 특정 저장소 내부의 설정. --local로 제어.

이 계층에서 하위 레벨이 상위를 덮어씁니다. 예를 들어, 저장소 내부의 설정은 사용자 수준보다 우선됩니다.

모든 설정과 출처 확인

[root@VM-0-17-centos ~]# git config --list --show-origin
file:/root/.gitconfig	user.name=John Doe
file:/root/.gitconfig	user.email=johndoe@example.com

태그: Git CentOS dnf source compilation configuration

5월 26일 01:02에 게시됨