Git config 설정하기


Git 을 사용하다가 새로운곳에 cloning 을 하거나 로컬 컴퓨터를 갈아 엎거나 하는 등의 경우에 git 환경을 새로 설정해 줘야 하는 경우가 생긴다. 가장 흔한 경우는 user.email과 user.name 이 지정되어 있지 않은 경우로, 명령을 실행하려고 하면 먼저 지정하고 나서 명령을 다시 실행하라는 메세지가 나오는 경우이다.

 

예를 들어 

$ git stash

를 실행했더니

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

이런 메세지가 나오는 경우이다.

 

이런 경우에 일단 현재 설정을 확인하려면 

$ git config --list
혹은 간단히 
$ git config -l

라고 입력하면 아래와 같이 현재 config 정보가 나오게 된다.

user.password=########
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=### 원격 저장소 주소
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
credential.helper=store

 

없는 설정을 추가하거나 기존의 설정을 변경하려면 git config 명령 뒤에 설정하고 싶은 항목을 적어 주면 된다.

--global 옵션을 붙이면 해당 사용자가 작업중인 모든 프로젝트에 해당 설정이 적용된다. 따로 --global 을 붙이지 않으면 자동으로 --local 옵션이 붙은것과 같이 되어 현재 작업중인 프로젝트에만 해당 설정이 적용된다. 

시스템의 모든 사용자와 모든 저장소에 설정을 적용하려면 --system 옵션을 붙이면 된다.

 

user.name 과 user.email 이 설정되어 있지 않다면 위처럼 목록에 보이지 않는다. 설정을 위해 다음 명령어를 입력하면 된다. 특별한 경우가 아니면 보통 --global 로 설정하게 되는것같다.

$ git config --global user.name "이름"
$ git config --global user.email "이메일 주소"

설정하려는 항목의 내용을 따옴표 안에 적어 주어야 한다.

 

적고 나서 다시 설정 내용을 확인해 보면

user.password=########
user.name=이름
user.email=이메일 주소
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=### 원격 저장소 주소
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
credential.helper=store

와 같이 새로 설정한 user.name과 user.email 이 반영되어 있는것을 볼 수 있다.

 

설정되어 있는 내용을 지우려면 --unset 옵션을 이용하면 된다.

$ git config --unset --global user.name "이름"
$ git config --unset --global user.email "이메일 주소"

위와 같이 하고 다시 git config -l 을 해 보면 해당 정보가 삭제된 것을 확인할 수 있다(global 로 설정하지 않은 경우는 global 옵션을 적지 않아야 적용된다).

TAGS: # git # git config


최근 글 목록