Fall in IT.

Git Alias 개념 및 사용방법 본문

기타

Git Alias 개념 및 사용방법

D.Y 2019. 2. 13. 23:32

Git Alias 개념 및 사용법 (Git 단축키 설정 방법)

개념
  • cmd에서 git을 사용하지 않고 git client를 사용하는 이유는 여러가지가 있겠지만, 그중에서 branch 흐름을 한눈에 쉽게 파악할 수 있기 때문입니다. cmd에서 git log 명령어를 통해 확인하긴 어렵기 떄문에 다양한 옵션을 추가하여 확인합니다.

$ git log --graph --abbrev-commit --decorate --format=format:'%C(cyan)%h%C(reset) - %C(green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(yellow)%d%C(reset)' --all

  • 매번 위와 같이 긴 명령어를 사용할 수 없기 떄문에 git 명령어 중 자주 사용되는 긴 명령어의 경우 단축키를 설정하여 사용합니다.

사용법
  • git 환경설정 파일 open

    $ vi ~/.gitconfig 

  • 하단에 아래 내용 추가
  • [alias]
        co = checkout
        rb = rebase -i
        st = status
        cm = commit
        pl = pull
        ps = push
        lg = log --graph --abbrev-commit --decorate --format=format:'%C(cyan)%h%C(reset) - %C(green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(yellow)%d%C(reset)' --all
        ad = add
        tg = tag -n
        df = diff
        br = branch
    



Git pull, fetch의 개념
  • git pull = git fetch + git merge FETCH_HEAD
  • git fetch는 원격브랜치만 update 한다.
  • git pull은 원격브랜치와 로컬브랜치를 모두 update한다.
  • 언제쓰지?
    • 신중하게 git의 데이터를 가져오고 싶을때, 결합은 나중에하고 원격 브랜치만 가져올 경우 사용한다.


알아두면 유용한 tip

  • 코드를 수정하고 반드시 stage에 올리는 작업인 git add를 수행하고, commit을 수행해야 합니다.
  • 이를 한번에 하는 명령어
    • git commit 옵션에 -a를 사용하면 add와 commit을 한번에 수행할 수 있습니다.
    • $ git commit -am “ok!”  


로컬에 이미 git 저장소가 존재할때, 원격 저장소와 연결하는 방법
  • $ git remote add origin https://github.com/leeduyoung/ex-opentutorials.git
    • 원격 저장소 이름을 origin으로 설정한다.
  • $ git push -u origin master 
    • -u 명령어를 통해서, 원격의 master와 로컬의 master를 연결한다. 


모두 즐거운 코딩하세요~



Comments