ToolStack
KO

Git Commands Cheatsheet

Git commands for commits, branches, undoing changes, and remotes

Your data never leaves the browser — all processing is done locally 0 server requests

01

Configuration & Setup

  • git config --global user.name "이름"

    Set the user name recorded in commits

  • git config --global user.email "메일주소"

    Set the email address recorded in commits

  • git config --global init.defaultBranch main

    Set the default branch name to main for new repositories

  • git init

    Initialize the current directory as a Git repository

  • git clone https://github.com/user/repo.git

    Clone a remote repository locally

  • git clone --depth 1 URL

    Shallow clone with only the latest commit (faster for large repos)

02

Basic Workflow — Status, Stage, Commit & Push

  • git status

    Show changed files and their staging status

  • git add .

    Stage all changes in the current directory

  • git add -p

    Interactively stage changes hunk by hunk

  • git commit -m "메시지"

    Commit staged changes with a message

  • git commit --amend

    Amend the last commit or edit its message ※ recommended before pushing only

  • git push

    Push commits to the remote repository

  • git push -u origin 브랜치명

    Push a new branch for the first time and set up tracking

  • git pull

    Fetch and merge remote changes (fetch + merge)

  • git fetch --all

    Fetch remote changes from all remotes without merging

03

Branches

  • git branch -a

    List all local and remote branches

  • git switch 브랜치명

    Switch to a branch (use git checkout for older Git versions)

  • git switch -c 새브랜치

    Create a new branch and switch to it immediately

  • git branch -d 브랜치명

    Delete a merged branch (-D to force-delete)

  • git merge 브랜치명

    Merge the specified branch into the current branch

  • git rebase main

    Rebase the current branch's commits on top of main

  • git rebase -i HEAD~3

    Interactively squash or edit the last 3 commits

  • git cherry-pick 커밋해시

    Apply a specific commit onto the current branch

04

Viewing History

  • git log --oneline --graph --all

    View commit history as a compact one-line graph

  • git log -p 파일명

    Show change history for a specific file with diffs

  • git diff

    Show unstaged changes in the working directory

  • git diff --staged

    Show changes that are staged for commit

  • git show 커밋해시

    Show the contents of a specific commit

  • git blame 파일명

    Show who last modified each line of a file and when

05

Undoing Changes

※ reset --hard and clean can permanently destroy work. Run git status first to review the current state.

  • git restore 파일명

    Discard working directory changes and restore the last committed state

  • git restore --staged 파일명

    Unstage a file while keeping the working directory changes

  • git reset --soft HEAD~1

    Undo the last commit but keep changes staged

  • git reset --hard HEAD~1

    Discard the last commit and all its changes ※ irreversible

  • git revert 커밋해시

    Create a new commit that reverses a given commit (safe for shared branches)

  • git stash

    Temporarily save uncommitted changes and clean the working directory

  • git stash pop

    Reapply the most recently stashed changes (use list to view all stashes)

  • git clean -fd

    Delete untracked files and directories ※ irreversible (use -n for a dry run)

06

Remotes & Tags

  • git remote -v

    Show configured remote repository URLs

  • git remote add origin URL

    Add a new remote repository

  • git tag -a v1.0.0 -m "릴리즈"

    Create an annotated tag with a message

  • git push origin --tags

    Push all tags to the remote repository

  • git fetch --prune

    Remove local references to branches deleted on the remote

Git: The Fundamental Workflow

Git's core workflow is: modify files → git add (stage) → git commit (save snapshot) → git push (share). Understanding that Git tracks snapshots (not differences) and that commits are permanent, content-addressed objects makes the rest of the commands much easier to reason about.

Branching is Git's killer feature. git switch -c new-branch creates and switches to a new branch. Merge with git merge or rebase with git rebase — merge for public branches, rebase for cleaning up local history.

⚠ git reset --hard, git clean -fd, and git push --force discard or overwrite data permanently. For shared branches, prefer git revert to create a safe undo commit.

FAQ

What is the difference between git merge and git rebase?
git merge creates a merge commit that joins two branches, preserving the full history. git rebase replays your commits on top of another branch, creating a linear history. Rebase produces a cleaner log but rewrites commit history — only use it on local or private branches, never on shared ones.
How do I undo the last commit without losing my changes?
Use git reset --soft HEAD~1. This removes the last commit but keeps the changes staged. If you also want to unstage them, use git reset --mixed HEAD~1 (the default). For completely discarding changes, use --hard, but this is irreversible.
How do I stash only specific files?
Use git stash push -m "description" path/to/file. This stashes only the specified file. You can then apply it back with git stash pop or git stash apply stash@{0}.

Related Tools