#Setup
| Command | Description | |
|---|---|---|
git config --global user.name "[name]" | Set user name | |
git config --global user.email "[email]" | Set email | |
git config --list | List all settings | |
git init | Initialize new repository | |
git clone [url] | Clone remote repository |
#Basic Commands
| Command | Description | |
|---|---|---|
git status | Check status | |
git add [file] | Stage file | |
git add . | Stage all changes | |
git commit -m "[message]" | Create commit | |
git commit -am "[message]" | Stage and commit | |
git push | Push to remote | |
git pull | Pull from remote | |
git fetch | Fetch without merge |
#Branches
| Command | Description | |
|---|---|---|
git branch | List branches | |
git branch [name] | Create new branch | |
git checkout [branch] | Switch branch | |
git checkout -b [name] | Create and switch | |
git switch [branch] | Switch branch (new) | |
git switch -c [name] | Create and switch (new) | |
git merge [branch] | Merge branch | |
git branch -d [name] | Delete branch | |
git branch -D [name] | Force delete |
#History
| Command | Description | |
|---|---|---|
git log | Commit history | |
git log --oneline | One line per commit | |
git log --graph | Show graph | |
git log -p | Show patches | |
git show [commit] | Show commit details | |
git diff | Show changes | |
git diff --staged | Staged changes | |
git blame [file] | Show line authors |
#Undo
| Command | Description | |
|---|---|---|
git restore [file] | Discard changes | |
git restore --staged [file] | Unstage file | |
git reset HEAD~1 | Undo last commit (keep changes) | |
git reset --hard HEAD~1 | Undo last commit (discard) | |
git revert [commit] | Revert commit (new commit) | |
git clean -fd | Remove untracked files |
#Stash
| Command | Description | |
|---|---|---|
git stash | Stash changes | |
git stash save "[message]" | Stash with message | |
git stash list | List stashes | |
git stash pop | Apply and remove stash | |
git stash apply | Apply stash (keep) | |
git stash drop | Drop stash | |
git stash clear | Clear all stashes |
#Remote
| Command | Description | |
|---|---|---|
git remote -v | List remotes | |
git remote add [name] [url] | Add remote | |
git remote remove [name] | Remove remote | |
git push -u origin [branch] | Set upstream and push | |
git push origin --delete [branch] | Delete remote branch |
#Tags
| Command | Description | |
|---|---|---|
git tag | List tags | |
git tag [name] | Create tag | |
git tag -a [name] -m "[msg]" | Create annotated tag | |
git push origin [tag] | Push tag | |
git push origin --tags | Push all tags |
#Advanced
| Command | Description | |
|---|---|---|
git rebase [branch] | Rebase | |
git rebase -i HEAD~[n] | Interactive rebase | |
git cherry-pick [commit] | Cherry-pick commit | |
git bisect start | Start bisect | |
git reflog | Reference log | |
git submodule add [url] | Add submodule |
#Frequently Asked Questions
이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.