Skip to content

Instantly share code, notes, and snippets.

@wnsgml972
Last active December 9, 2019 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wnsgml972/44eca250bfb77095558253909b2d08c7 to your computer and use it in GitHub Desktop.
Save wnsgml972/44eca250bfb77095558253909b2d08c7 to your computer and use it in GitHub Desktop.

Git 명령어 정리

Config

Init Global Config

git config --global user.name "KimJunHee"
git config --global user.email wnsgml972@gmail.com
git config --global core.editor "sublime_text -w"
git config --global merge.tool vimdiff
git config --global color.ui true

Git 계정 여러개 사용하기

Global Git Config 확인하기

  1. vi ~/.gitconfig에서 설정을 추가하면 된다.
  2. 아래 설정들은 Global Space로 적용된다.
[core]
  precomposeunicode = true
  quotepath = false
[user]
  name = Kwon Young Jae
  email = kyoje11@gmail.com

특정 Directory에 Git config 설정 하기

  1. vi ~/.gitconfig에 아래 내용을 추가한다.
  2. Directory 위치는 ~/Desktop/private 아래에 해당한다.
[includeIf "gitdir:~/Desktop/private/"]
  path = .gitconfig-private

~/.gitconfig-private 파일 생성하기

  1. vi ~/.gitconfig-private
[user]
  name = nesoy
  email = kyoje11@kakao.com

설정된 Config 확인하기

  1. private Directory에 들어가서 git init을 하면 설정된 name과 email이 반영된 것을 확인할 수 있다.

Reference



Branch

  • 브랜치 생성
git checkout -b {branch}
git push {remote} {branch}
  • 특정 브랜치에서 내려 받기
git clone -b {branch} {remote}
  • branch 삭제
git branch --delete {branch}
git push {remote} :{branch}
  • branch 조회
git branch -r (remote만 조회)
git branch -a (로컬까지 모두 조회)



Remote

  • remote 조회
git remote -v    (원격 저장소 url 조회)
git ls-remote    (refs 조회)
git remote show  (remote 이름 조회)
  • remote 삭제
git remote remove {remote}
  • remote 추가
git remote add {remote}



Merge

git checkout {branch}  ->  master 아니면 브랜치 변경
git merge {branch}
git push -u origin master

-u 옵션은 향후에 수정된 내용을 push 혹은 pull하기 쉽게 할 수 있도록 하는 옵션이다.



push

git push -u {remote} {branch}



Log

git log
git shortlog




ETC..

원격 브랜치에서 내려 받아 로컬에 브랜치 생성하기

git remote update
git branch -r
git checkout -t {{remote}}

원격 저장소의 브랜치 참고만하기!!

아무런 옵션없이 원격 저장소의 branch를 checkout 하면 ‘detached HEAD’ 상태로 소스를 보고 변경 해볼 수도 있지만, 변경사항들은 commit, push 할 수 없으며 다른 branch로 checkout하면 사라진다.

git checkout {{remote}}

특정 시간 이후로 내가 커밋한 내용 모두 출력하여 마크다운으로 만들어주기

  • 해당 깃 디렉토리에서 시작 -> markdown 파일
  • author에 git id 입력
  • since에 해당 첫 시작 날짜 입력
git log --pretty="> [%h] %ad - %s"$'\n' --author=kjh0121 --since="2019-07-11" --no-merges > ../my_commit_log.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment