git:ko

git

TCP 9418

usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           [--config-env=<name>=<envvar>] <command> [<args>]
 
# agent가 실행 안 된 것 → 먼저 실행
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
  • git <command>
  • start a working area (see also: git help tutorial)
  • git clone [<options>] [–] <repo> [<dir>]: Clone a repository into a new directory
    • -v, –verbose: be more verbose not
    • -q, –quiet: be more quite not
    • –progress: force progress reporting not
  • git init [<options>] [<directory>]: Create an empty Git repository or reinitialize an existing one
    • –bare: 로컬 서버에 저장소 생성.
  • work on the current change (see also: git help everyday)
  • git add [<options>] [–] <pathspec>…: Add file contents to the index
  • git mv [<options>] [–] <archive_name>: Move or rename a file, a directory, or a symlink
  • git restore [<options>] [–] <archive_name>: Restore working tree files
  • git rm [<options>] [–] <archive_name>: Remove files from the working tree and from the index
  • examine the history and state (see also: git help revisions)
  • git bisect [<options>] [–] <archive_name>: Use binary search to find the commit that introduced a bug
  • git diff [<options>] [–] <archive_name>:Show changes between commits, commit and working tree, etc diff
  • git grep [<options>] [–] <archive_name>: Print lines matching a pattern
  • git log [<options>] [–] <archive_name>: Show commit logs log
  • git show [<options>] [–] <archive_name>: Show various types of objects
  • git status [<options>] [–] <archive_name>: Show the working tree status
  • grow, mark and tweak your common history
  • git branch [<options>] [–] <archive_name>: Record changes to the repository
  • git commit [<options>] [–] <archive_name>: Join two or more development histories togeth
  • git merge [<options>] [–] <archive_name>: Reapply commits on top of another base tip
  • git rebase [<options>] [–] <archive_name>: Reset current HEAD to the specified state
  • git reset [<options>] [–] <archive_name>: Switch branches
  • git switch [<options>] [–] <archive_name>: Create, list, delete or verify a tag object signed with GPG
  • collaborate (see also: git help workflows)
  • git fetch [<options>] [–] <archive_name>: Download objects and refs from another repository
  • git pull [<options>] [–] <archive_name>: Fetch from and integrate with another repository or a local branch
  • git push [<options>] [–] <archive_name>: Update remote refs along with associated objects

help

  • git cat-file -p <hashcode>: SHA-1에 해당하는 객체(.git/objects/..) 내용 출력
  • git cat-file -p <tag>: tag에 해당하는 객체(.git/objects/..) 내용 출력
  • git cat-file commit HEAD: HEAD가 가리키는 커밋 확인
  • git ls=file –stage: 인덱스 파일 실제 내용 확인
  • git tag: 현재 생성된 태그 리스트
  • git cherry-pick <commit>: 특정 커밋을 이 브랜치로 가져오기
  • git reflog: reference log 보기
  • git reflog show <branch>: 특정 브랜치의 레퍼런스 로그 보기
  • git reflog -all: 모든 브랜치의 레퍼런스 로그 보기
  • -u name, –set-upstream name: upstream 설정(원본. origin)

커밋 변경 내용을 통합하여 확인

  • git diff [<options>] [–] <archive_name>:Show changes between commits, commit and working tree, etc
    • –stat [branch | ragne] 범위 또는 브랜치의 변경 내용 요약
      • range: <commit_hash_1>..<commit_hash_2> 범위의 변경 내용 요약해서 표시.
        • HEAD~5..HEAD 가장 최근 5개의 커밋 변경 내용 요약
    • – path: 특정파일로 한정

커밋 히스토리

  • git log [<options>] [–] <archive_name>: Show commit logs
    • –stat: 각 커밋마다 변경된 파일 목록과 함께 파일별 수정 라인, 최종 변경요약을 보여줌
    • –shoartstat: -stat보다 간결하게, 변경된 파일 수와 전체 추가/삭제 라인수만 보여줌
    • –oneline: 커밋 히스토리를 한 줄씩 보여줌
    • -p path: 특정 파일의 변경내역 확인
  • git branch [<options>] [–] <archive_name>: Record changes to the repository
  • git branch new_branch base_branch: base_branch에서 new_branch생성.
  • –delete branch, -d branch: 로컬 브랜치 삭제
  • git switch branch: 해당 branch로 이동
    git checkout branch checkout(legacy)
  • git switch –create branch: 해당 branch생성 후 이동
    git checkout -b branch checkout(legacy)
  • git branch -f branch origin/branch: 특정 branch를 원격 origin/branch로 강제 업데이트
  • git rebase branch branch(main)로 rebase.
  • git merge [<options>] [–] branch: branch merge into this
  • git commit [<options>] [–] <archive_name>: Join two or more development histories togeth
    • –allow-empty: 빈 커밋(변경사항 없음) 생성
    • -m message: 커밋 메시지 지정
    • –amend: 기존 커밋에 수정/추가
  • git push [<options>] [–] <archive_name>: Update remote refs along with associated objects
    • –set-upstream remote branch 신규 생성한 로컬 브랜치를 원격(remote)에 새로운 브랜치((branch)로 푸시
    • –all 모든 브랜치 업로드

set-upstream이 필요한 경우

  • git pull [<options>] [–] <archive_name>:
    • –ff-only Fast Forward Only
    • –default Fast Forward Only
    • –rebase rebase 재배치
    • –all 모든 브랜치
  • git fetch [<options>] [–] <archive_name>: 원격 저장소의 브랜치 정보를 가져옴(로컬에 직접적인 영향은 없음). Pull 전 선행 명령어
    • –all 모든 브랜치

현재 진행상태를 임시 저장

  • git stash: 새로운 stash 생성
    git stash push
    git stash save 삭제예정
  • git stash list: stash 확인
  • git stash apply:
  • git stash pop: 스태시에서 꺼내기
$git config --list
$git config --global -e
$git config --global core.editor "code" # vscode 로 에디터 설정
$git config --global core.editor "code --wait" # 잠금
$git config --global user.name "zerotymer"
$git config --global user.email "[email protected]"
$git config user.name # zerotymer
$git config user.email # [email protected]
$git config --global core.autocrlf true # 캐리지 리턴 삭제. windows-tru, mac-input으로 설정.
$ # 반영구적 인증 저장
$git config credential.helper 'cache --timeout=3600' # s단위 인증저장

Alias

  • git config –global alias.<alias> <command>: 별칭 설정
  • git <alias>: 별칭 호출
  • git config credential.helper<alias> store: 인증 정보 저장
  • git config –list: 설정 확인
  • git config –unset key: 설정 확인
  • git svn: Subversion을 클라이언트로 사용.
  • git fast-import: 다른 버전 관리시스템에서 데이터를 Git으로 가져옴
  • git reset commit-hash 변경사항 되돌리기(Rollback)
  • –soft: 마지막 커밋 취소 후 staging 상태 유지
  • –mixed: 마지막 커밋 취소 후 파일은 working directory로 이동
  • –hard: 마지막 커밋 및 변경사항 모두 폐기
  • commit-hash: 특정 커밋
  • HEAD~num: HEAD 커밋에서 num 전 커밋
  • git revert commit-hash 이전 버전으로 돌리는 취소 커밋 생성
  • git worktree add PATH BRANCH 현재 저장소에 연결된 브랜치를 해당 경로에 만듦(../name 등 별도 경로에 할 것)
    • -b 해당 브랜치를 생성
  • git worktree list 현재 저장소에 연결된 worktree 확인
  • git worktree remove PATH 연결 제거
  • git worktree prune 연결정보 강제 정리

update-index

  • git update-index –skip-worktree PATH 추적중인 파일을 작업 디렉토리에 쓰는것을 호피
# Git global setup
git config --global user.name "NAME"
git config --global user.email "EMAIL"
 
# Create a new repository
git clone REPOSITORY
cd folder
git switch --create main
touch README.md
git add README.md
git commit -m "add README"
git push --set-upstream origin main
 
# Push an existing folder
cd existing_folder
git init --initial-branch=main
git remote add origin REPOSITORY
git add .
git commit -m "Initial commit"
git push --set-upstream origin main
 
# Push an existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin REPOSITORY
git push --set-upstream origin --all
git push --set-upstream origin --tags
 
# Remove Git remote
git remote remove origin
 
# git alias
# git lg: 로그 예쁘게
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
 
# branch pull 기본 설정
git config --global pull.rebase false

프로젝트 내부의 독립된 Git 저장소. 메인 프로젝트에서 단순히 특정 커밋 SHA만 저장되고, 독립 저장소는 별도로 관리

  • git submodule add [<switches>…] <archive_name>
  • git submodule init [<switches>…] <archive_name>
  • git submodule update <archive_name>
    • –init –recursive 중첩된 서브모듈까지 전부 초기화
    • –remote 서브모듈을 원격 최신 커밋으로 갱신
  • git submodule foreach 'command': 모든 서브모듈에 일괄 명령 수행
  • git submodule clone –recurse-submodules repo 클론 시 자동으로 서브모듈까지 가져옴

하나의 저장소 내부에 병합 커밋 이력은 별도로 추적

  • git subtree add –prefix=path repo_url repo_branch 다른 repo를 특정 경로(path)로 병합
    • –squash 이력압축
  • git subtree pull –prefix=path repo_url repo_branch 원격 변경사항 병합
  • git subtree push –prefix=path repo_url repo_branch 하위 저장소로 변경사항 푸시
  • git/ko.txt
  • 마지막으로 수정됨: 2026/05/27 10:36
  • 저자 writer