git 명령어 정리

GitHub을 혼자 사용할 때는 기본만 알아도 큰 불편함이 없었지만, 여러 사람들과 함께 사용하다 보니, 익숙치 않은 명령어를 사용할 때마다 검색해서 하는 것이 귀찮아서 블로그에 간단히 정리해둔다.

 

  • GitHub에 여러 계정의 ssh key 사용 (Host 키워드를 사용하여 alias 방법)
    $ vi ~/.ssh/config
    
    Host HOSTA 
        HostName github.com
        User git
        IdentityFile ~/.ssh/HOSTA_rsa
    
    Host HOSTB
        HostName github.com
        User git
        IdentityFile ~/.ssh/HOSTB_rsa
    $ git clone git@HOSTA:<path>/xxx.git .
  • Branch 관리
    • 생성
      $ git branch <branch_name> <reference_branch>
      $ git checkout -b <branch_name> # branch 생성 후, checkout
      $ git push <remote_repo> <branch_name>
    • 삭제
      $ git branch -d <branch_name>
      $ git branch -D <branch_name> # --delete --force 
      $ git push <remote_repo> -d <branch_name> # --delete 
    • 변경
      $ git branch -m <branch_name> <new_name> 
    • 병합
      $ git branch checkout <branch_name>
      $ git merger main # main의 branch로 변경사항 적용
      
  •  Submodule 관리
    • 생성
      $ git submodule add <repo_url> <local_path>
      $ git submodule init
      $ git submodule update
      $ vi .gitmodules
       
      [submodule "Core/Src/extlib/graphic/LVGL/lvgl"]
          path = Core/Src/extlib/graphic/LVGL/lvgl
          url = git@github.com:lvgl/lvgl.git
    • 삭제
      $$ git submodule deinit -f <local_path>
      $ rm -rf .git/modules/<local_path>
      $ git rm -f <local_path>
    • 업데이트
      $ git clone git@github.com:id/xxx.git .
      $ git submodule update --init --recursive
  • 계속 업데이트 중...