커밋, 브랜치, 병합, 리베이스, 리모트 등의 필수 Git 명령어.
git config --global user.name "Name"설정 및 구성Set global author name
예: git config --global user.name "Jane Doe"
git config --global user.email "email"설정 및 구성Set global author email
예: git config --global user.email "[email protected]"
git config --list설정 및 구성List all configuration settings
git config --global core.editor "code"설정 및 구성Set VS Code as default editor
git config --global alias.<alias> <cmd>설정 및 구성Create a command alias
예: git config --global alias.st status
git init설정 및 구성Initialize a new local repository
git init <dir>설정 및 구성Initialize a repo in a specific directory
예: git init my-project
git clone <url>설정 및 구성Clone a remote repository
예: git clone https://github.com/user/repo.git
git clone <url> <dir>설정 및 구성Clone into a specific folder
예: git clone https://github.com/user/repo.git my-dir
git status스테이징 및 기본Show working tree status
git status -s스테이징 및 기본Short/compact status output
git add <file>스테이징 및 기본Stage a specific file
예: git add README.md
git add .스테이징 및 기본Stage all changes in current directory
git add -p스테이징 및 기본Interactively stage hunks of changes
git commit -m "msg"스테이징 및 기본Commit staged changes with a message
예: git commit -m "feat: add login page"
git commit -am "msg"스테이징 및 기본Stage tracked files and commit in one step
git commit --amend파괴적스테이징 및 기본Modify the most recent commit (message or content)
git diff스테이징 및 기본Show unstaged changes
git diff --staged스테이징 및 기본Show staged changes (vs last commit)
git diff <branch1>..<branch2>스테이징 및 기본Compare two branches
예: git diff main..feature
git rm <file>스테이징 및 기본Remove a file from working tree and index
예: git rm old-file.txt
git rm --cached <file>스테이징 및 기본Untrack a file without deleting it
예: git rm --cached secret.txt
git mv <old> <new>스테이징 및 기본Move or rename a tracked file
예: git mv old.js new.js
git branch브랜치 및 병합List local branches
git branch -a브랜치 및 병합List all branches (local + remote)
git branch <name>브랜치 및 병합Create a new branch
예: git branch feature/auth
git checkout <branch>브랜치 및 병합Switch to an existing branch
예: git checkout main
git checkout -b <branch>브랜치 및 병합Create and switch to a new branch
예: git checkout -b feature/auth
git switch <branch>브랜치 및 병합Switch branches (modern syntax)
예: git switch main
git switch -c <branch>브랜치 및 병합Create and switch (modern syntax)
예: git switch -c feature/auth
git branch -d <branch>브랜치 및 병합Delete a merged branch
예: git branch -d feature/auth
git branch -D <branch>파괴적브랜치 및 병합Force delete a branch (unmerged too)
예: git branch -D feature/old
git branch -m <old> <new>브랜치 및 병합Rename a branch
예: git branch -m old-name new-name
git merge <branch>브랜치 및 병합Merge a branch into current branch
예: git merge feature/auth
git merge --no-ff <branch>브랜치 및 병합Merge with a merge commit (no fast-forward)
git merge --squash <branch>브랜치 및 병합Squash all commits from branch into one staged change
git merge --abort브랜치 및 병합Abort an in-progress merge
git remote -v원격 작업List remote connections with URLs
git remote add <name> <url>원격 작업Add a new remote
예: git remote add origin https://github.com/user/repo.git
git remote remove <name>원격 작업Remove a remote connection
예: git remote remove origin
git remote rename <old> <new>원격 작업Rename a remote
예: git remote rename origin upstream
git fetch원격 작업Download all changes from remote (no merge)
git fetch <remote>원격 작업Fetch from a specific remote
예: git fetch origin
git pull원격 작업Fetch and merge changes from remote
git pull --rebase원격 작업Fetch and rebase onto remote branch
git push <remote> <branch>원격 작업Push branch to remote
예: git push origin main
git push -u origin <branch>원격 작업Push and set upstream tracking
예: git push -u origin feature/auth
git push --force-with-lease파괴적원격 작업Safe force push (fails if others pushed)
git push --tags원격 작업Push all tags to remote
git push origin --delete <branch>파괴적원격 작업Delete a remote branch
예: git push origin --delete feature/old
git restore <file>파괴적변경 취소Discard changes in working directory
예: git restore index.html
git restore --staged <file>변경 취소Unstage a file (keep changes)
예: git restore --staged index.html
git reset HEAD <file>변경 취소Unstage a file (older syntax)
예: git reset HEAD index.html
git reset --soft HEAD~1변경 취소Undo last commit, keep changes staged
git reset --mixed HEAD~1변경 취소Undo last commit, unstage changes (default)
git reset --hard HEAD~1파괴적변경 취소Undo last commit, discard all changes
git reset --hard <commit>파괴적변경 취소Reset to a specific commit, discard everything after
git revert <commit>변경 취소Create a new commit that undoes a specific commit
예: git revert a1b2c3d
git revert HEAD변경 취소Revert the most recent commit
git clean -fd파괴적변경 취소Remove untracked files and directories
git clean -n변경 취소Dry run: show what would be cleaned
git stash스태시Stash current working directory changes
git stash push -m "msg"스태시Stash with a descriptive message
예: git stash push -m "WIP: auth feature"
git stash list스태시List all stashes
git stash pop스태시Apply most recent stash and remove it
git stash apply stash@{n}스태시Apply a specific stash without removing
예: git stash apply stash@{0}
git stash drop stash@{n}스태시Delete a specific stash
예: git stash drop stash@{0}
git stash clear파괴적스태시Remove all stashes
git stash branch <branch>스태시Create a branch from a stash
예: git stash branch feature/from-stash
git rebase <branch>리베이스 및 고급Rebase current branch onto another
예: git rebase main
git rebase -i HEAD~n리베이스 및 고급Interactive rebase for last n commits
예: git rebase -i HEAD~3
git rebase --continue리베이스 및 고급Continue rebase after resolving conflicts
git rebase --abort리베이스 및 고급Abort an in-progress rebase
git cherry-pick <commit>리베이스 및 고급Apply a specific commit to current branch
예: git cherry-pick a1b2c3d
git cherry-pick <c1>..<c2>리베이스 및 고급Apply a range of commits
예: git cherry-pick a1b2c3d..f6e5d4c
git bisect start리베이스 및 고급Start binary search for a bug
git bisect good <commit>리베이스 및 고급Mark a commit as good in bisect
git bisect bad <commit>리베이스 및 고급Mark a commit as bad in bisect
git bisect reset리베이스 및 고급End bisect session
git worktree add <path> <branch>리베이스 및 고급Check out a branch into a separate directory
git log검사 및 로그Show commit history
git log --oneline검사 및 로그Compact one-line log
git log --oneline --graph --all검사 및 로그Visual branch graph in terminal
git log -n <count>검사 및 로그Show last N commits
예: git log -n 5
git log --author="name"검사 및 로그Filter commits by author
예: git log --author="Jane Doe"
git log --since="2 weeks ago"검사 및 로그Show commits since a date
git log -p <file>검사 및 로그Show changes to a specific file over time
예: git log -p README.md
git log --follow <file>검사 및 로그Follow renames of a file in history
git show <commit>검사 및 로그Show details of a specific commit
예: git show a1b2c3d
git blame <file>검사 및 로그Show who last modified each line
예: git blame src/app.tsx
git shortlog -sn검사 및 로그Summarize commits by author
git reflog검사 및 로그Show history of HEAD movements (recovery tool)
git grep "pattern"검사 및 로그Search working directory for a pattern
예: git grep "TODO"
git tag태그List all tags
git tag <name>태그Create a lightweight tag
예: git tag v1.0.0
git tag -a <name> -m "msg"태그Create an annotated tag
예: git tag -a v1.0.0 -m "Release v1.0.0"
git tag -a <name> <commit>태그Tag a past commit
예: git tag -a v0.9.0 a1b2c3d
git show <tag>태그Show tag metadata and commit
예: git show v1.0.0
git push origin <tag>태그Push a specific tag to remote
예: git push origin v1.0.0
git push origin --tags태그Push all tags to remote
git tag -d <tag>태그Delete a local tag
예: git tag -d v1.0.0
git push origin --delete <tag>태그Delete a remote tag
예: git push origin --delete v1.0.0
git merge는 머지 커밋을 생성하여 두 브랜치를 결합하고 두 브랜치의 전체 히스토리를 보존합니다. git rebase는 한 브랜치의 커밋을 다른 브랜치로 이동시켜 히스토리를 재작성하여 선형적이고 깔끔한 커밋 히스토리를 만듭니다. 공개 브랜치와 공유 작업에는 merge를, 병합 전 로컬 피처 브랜치 정리에는 rebase를 사용하세요.
git reset --soft HEAD~1을 사용하면 변경 사항을 스테이징된 상태로 유지하면서 마지막 커밋을 취소할 수 있습니다. git reset HEAD~1(또는 --mixed)은 변경 사항의 스테이징을 해제하지만 작업 디렉토리에는 유지합니다. git reset --hard HEAD~1은 커밋과 모든 변경 사항을 영구적으로 삭제합니다(파괴적 작업).
git fetch는 원격에서 변경 사항을 다운로드하지만 현재 브랜치에 병합하지는 않습니다. 원격 추적 브랜치(origin/main)를 업데이트합니다. git pull은 git fetch + git merge입니다(또는 --rebase 플래그를 사용한 git rebase). 변경 사항을 통합하기 전에 검사하고 싶을 때는 fetch를 사용하세요.
충돌하는 머지/리베이스 후, Git은 충돌된 파일을 '<<<<<<', =======, >>>>>> 마커로 표시합니다. 각 충돌 파일을 열어 어떤 변경 사항을 유지할지 수동으로 선택하고, 마커를 제거한 다음 git add <파일>로 해결된 파일을 스테이징하고 git merge --continue 또는 git commit으로 완료합니다.