사용자 도구

사이트 도구


git

문서의 이전 판입니다!


git

Ubuntu 최신 버전 install

sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git

Client 설정

  • https 관련 오류 발생시 env GIT_SSL_NO_VERIFY=true 붙여서 실행
  • 기본 git 사용자 정보 설정 git config --global이면 전체 시스템 공통 설정 --global 빼면 해당 리포지토리 지역 설정
    git config --global user.email "your@email.com"
    git config --global user.name "사용자명"
     
    # push/pull 기본설정 - 현재 브랜치에 대해서만 작동
    git config --global push.default simple
     
    # Windows에서 파일 모드 변경으로 인한 Update 방지
    git config --global core.filemode false
     
    # Mac OS X 유니코드 문제? 아직도 발생하나?
    # git config --global core.precomposeunicode true
    • git 1.7.12 이상 버전 사용
    • git config --global core.precomposeunicode true
      • 이걸 해도 자소 분리 현상이 발생하면 user.name을 다시 설정할 것.
    • SourceTree 사용자는 Preferences에서 “Allow SourceTree to modify your global Mercurial and Git configuration files” 체크 해제

Directory별 Include 설정

  • Git - git-config Documentation IncludeIf 구문으로 작업 디렉토리별로 기본 git 설정을 할 수 있다.
  • ~/.gitconfig
    [includeIf "gitdir:~/my-personal-projects/"] #마지막 "/" 필수
      path = .git_personal_projects
  • ~/.git_personal_proejcts
    [user]
      email = kwon37xi@gmail.com
      name = KwonNamSon
  • includeIf 는 맨 마지막에 두는 것이 좋다. 이 이후에 나오는 설정은 includeIf에 있는 설정을 덮어쓴다.

Ubuntu Git 최신 버전

Password Cache

  • HTTP(S) 프로토콜의 경우 명령행에서는 비밀번호 저장해두기가 곤란하다. 그래서 캐시를 사용한다.
  • Linux에서는 다음 처리로 간편하게 캐시가 끝난다.
    # 기본 캐시 시간 15분
    git config --global credential.helper cache
     
    # 캐시 시간 지정
    git config --global credential.helper 'cache --timeout=7200'

libsecret 기반 gnome-keyring credential

sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret

SSH 인증 저장소

Password with Gnome-Keyring : Deprecated from 2014

Password with kde

Windows

Git Diff -> meld

Git Mergetool -> meld

  • 전역 설정
    git config --global merge.tool meld

Git Diff -> vimdiff

  • ~/.gitconfig
    [diff]
      external = git_diff_wrapper
    [pager]
      diff =
  • ~/bin/git_diff_wrapper
    #!/bin/sh
    vimdiff "$2" "$5"
  • 설정의 external 무시하고 vim을 pager로
    git diff --no-ext-diff -w | vim -R -

.gitignore

*.exe  # 모든 .exe 파일을 ignore 하되
!node.exe  # node.exe 는 ignore 하지 않는다. 상위 설정을 아래에서 덮어씀.

Global .gitignore

# Create a ~/.gitignore in your user directory
cd ~/
touch .gitignore
 
# Exclude bin and .metadata directories
echo "bin" >> .gitignore
echo ".metadata" >> .gitignore
echo "*~" >> .gitignore
echo "target/" >> .gitignore
 
# Configure Git to use this file
# as global .gitignore
 
git config --global core.excludesfile ~/.gitignore 

Git hook

  • 기본적으로는 projectdir/.git/hooks에 후킹 파일을 둔다.
  • 2.9 부터는 projectdir/.githooks 에 후킹 스크립트를 넣는다.
  • 전역 Hook 파일 설정 (git 2.9+)
    git config --global core.hooksPath /path/to/my/centralized/hooks

Commit Template

$HOME/.gitmessage.txt 파일에 기본 커밋 메시지를 작성해 두고서,

git config --global commit.template $HOME/.gitmessage.txt

https certificat problem

  • 특히 윈도우 Cygwin에서 아르와 같은 오류가 발생한다. https로 clone할 때.
    Cloning into 'projectName'...
    error: error setting certificate verify locations:
      CAfile: /usr/ssl/certs/ca-bundle.crt
      CApath: none while accessing https://code.google.com/p/projectName/info/refs
    fatal: HTTP request failed
  • 해결책 1 - SSL 인증 무시
    # 환경변수로 무시
    export GIT_SSL_NO_VERIFY=true
     
    # 아니면 GIT 설정으로 무시
    git config --global http.sslVerify false
  • 인증서 깔아주기
    mkdir ~/certs
    curl http://curl.haxx.se/ca/cacert.pem -o ~/certs/cacert.pem
     
    # ~/.gitconfig 편집
    [http]
    sslCAinfo = /home/radium/certs/cacert.pem

독립 리포지토리 여러개를 하나로 묶기

Bash Prompt

  • Powerline 사용시 bash 테마를 default_leftonly로 지정하면 아래 과정이 불필요하다.
  • Bash 프롬프트에 Git Branch 이름 보여주기
    mkdir -p ~/.local/bin
    curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.local/bin/git-prompt.sh
     
    # edit .bashrc
    source ~/.local/bin/git-prompt.sh
    export PS1='이런저런 내용 \$(__git_ps1) 나머지 '
    # 실예 녹색 프롬프트
    export PS1='\[\e[1;32m\][\u@\h \W$(__git_ps1)]\$\[\e[0m\] '
     
    # 실예 컬러 프롬프트
    export PS1="\[\033[01;32m\][\[\033[01;33m\]\u\[\033[01;36m\]@\[\033[01;31m\]\h\[\033[01;37m\]:\[\033[01;34m\]\w\[\033[01;32m\]\$(__git_ps1)]\[\033[01;35m\]\\$\[\033[00m\] "

bash auto completion

  • 대부분의 리눅스는 git 을 설치하면 이미 bash-completion 설정 파일을 함께 설치한다.
    source /etc/bash_completion.d/git
    # or
    source /usr/share/bash-completion/completions/git
  • Arch/Manjaro
    sudo pacman -S git bash-completion
    # shell 재실행

환경변수

  • GIT_CURL_VERBOSE=1 : HTTP(S)에서 cURL 요청 주고 받는 것을 콘솔에 출력한다.

문제 해결

HTTP(S) 에서 비밀번호를 물어보지 않음

Git Hosting

Git 관련 애플리케이션

빈 디렉토리 (empty directory) 유지

find . -type d -empty -exec touch {}/.gitkeep \;

Windows 등에서 파일 chmod 변경 - 특히 실행(x) 권한

  • 아래는 Linux/*nix 계열에서는 불필요하고 작동하지도 않았다. 그냥 chmod 명령을 직접사용하면됨.
  • git ls-files --stage 명령으로 파일 권한 확인. 보통 100644로 돼 있음.
  • git update-index --chmod=+x 'name-of-shell-script' : 권한에 x 추가
  • git ls-files --stage로 다시 확인해보면 100755로 변경됨.
  • commit 한다.

문제 해결

참조

git.1596547718.txt.gz · 마지막으로 수정됨: 2020/08/04 22:28 저자 kwon37xi