[git] username(author) 설정

EMMA·2022년 7월 6일
0
post-thumbnail

Setting username in Git

첫 업무 인수인계를 받을 당시 사수가 직접 branch를 만들어줬는데,
그 후에 username 설정 없이 add/commit을 올렸더니 사수 이름으로 author가 찍힌 채 log가 찍혀버렸다.

그래서 username 설정과 관련 배운 겸, 정리해본다.

Git username 설정하기

Git uses a username to associate commits with an identity. The Git username is not the same as your GitHub username.

username을 설정하려면 아래 2가지를 입력하면 된다.

  • username
$ git config --global user.name [username]

#설정 확인 
$ git config --global user.name
>>> username  
  • user email (github email)
$ git config --global user.email [email]

#설정 확인 
$ git config --global user.email
>>> email 

아래 명령어를 실행하면 ~/.gitconfig 에 정보가 추가된다.

$ cat ~/.gitconfig

username의 경우, github의 username과 동일할 필요는 없다.
github과는 email로 매칭하기 때문이다. 그래서 동일한 email로 작성하고, commit - push를 하면 해당 이메일의 gitHub 사용자로 매칭된다.

따라서, 설정한 이메일이 잘못된 것이어도, 등록하면 github은 그 이메일로 바로 매칭시켜버린다. 즉 작성자가 애초에 보장되지 않는다.

이 때 사용하는 것이 GPG인증이며, GPG인증을 거치면 작성자 본인임이 확인되며 commit에 verified 마크가 붙는다.


Git username 설정하기 - 저장소 별 설정

저장소 별로 설정하고 싶으면, 아래와 같이 설정하면 된다.
저장소 별 설정은 global 설정보다 우선시 된다.

$ git config user.name [username]
$ git config user.email [email] 

해당 저장소의 설정 확인 명령어는 아래와 같다.

$ git config user.name
$ git config user.email

Git username 설정 삭제하기

삭제하는 명령어는 아래와 같다.

#global 설정 삭제 
$ git config --global --unset user.name
$ git config --global --unset user.email 

#저장소 설정 삭제
$ git config --unset user.name
$ git config --unset user.email

add/commit 후 author 변경하기

이미 commit한 상태에서 author를 변경해야 하는 경우다.

$ git commit --amend --author "username <user email>"


참고 자료
https://docs.github.com/en/get-started/getting-started-with-git/setting-your-username-in-git
https://www.lainyzine.com/ko/article/how-to-set-git-repository-username-and-email/#%EB%A1%9C%EC%BB%AC%EC%97%90%EC%84%9C-%EA%B8%B0%EB%B3%B8%EA%B0%92%EC%9C%BC%EB%A1%9C-%EC%82%AC%EC%9A%A9%ED%95%A0-git-%EC%82%AC%EC%9A%A9%EC%9E%90-%EC%9D%B4%EB%A6%84%EA%B3%BC-%EC%9D%B4%EB%A9%94%EC%9D%BC-%EC%84%A4%EC%A0%95global-%EC%98%B5%EC%85%98

profile
예비 개발자의 기술 블로그 | explore, explore and explore

0개의 댓글