Git
๐ ๏ธ ์์ด์ ํธ ์คํฌ
npx -y skills add DaleStudy/skills --skill gitAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Git ๋ฒ์ ๊ด๋ฆฌ ๋ชจ๋ฒ ๊ด๋ก ๋ฐ ์ํฌํ๋ก์ฐ ๊ฐ์ด๋. ๋ค์ ์ํฉ์์ ์ฌ์ฉ: (1) Git ์ปค๋ฐ ๋ฉ์์ง ์์ฑ ์ (Conventional Commits ๊ท์น ์ ์ฉ), (2) ๋ธ๋์น ์์ฑ ๋ฐ ๊ด๋ฆฌ ์ (GitHub Flow ๊ธฐ๋ฐ), (3) PR ์์ฑ ๋ฐ ๋ณํฉ ์ ๋ต ์ ํ ์, (4) Git ํ์คํ ๋ฆฌ ์ ๋ฆฌ ์์ ์ (rebase, squash, cherry-pick), (5) Merge conflict ํด๊ฒฐ ์, (6) 'git', '.git', 'commit', 'branch', 'merge', 'rebase' ํค์๋๊ฐ ํฌํจ๋ ์์ ์
The file declares its own license as MIT. That is the authorโs claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
12.5 KB, as published. Nobody here has run it
Git
Git ๋ฒ์ ๊ด๋ฆฌ ๋ชจ๋ฒ ๊ด๋ก ๋ฐ ์ํฌํ๋ก์ฐ ๊ฐ์ด๋.
์ปค๋ฐ ๋ฉ์์ง ์ปจ๋ฒค์
Conventional Commits ์ฌ์ฉ
์ปค๋ฐ ๋ฉ์์ง๋ <type>: <description> ํ์์ ๋ฐ๋ฅธ๋ค:
feat: add form validation to login page
fix: prevent duplicate email check error on signup
docs: add installation guide to README
refactor: extract auth logic into separate module
test: add payment feature tests
chore: update dependencies
์ฃผ์ ํ์
| ํ์ | ์ค๋ช | ์์ |
|---|---|---|
feat | ์๋ก์ด ๊ธฐ๋ฅ ์ถ๊ฐ | feat: add dark mode support |
fix | ๋ฒ๊ทธ ์์ | fix: prevent token deletion on logout |
docs | ๋ฌธ์ ๋ณ๊ฒฝ (์ฝ๋ ๋ณ๊ฒฝ ์์) | docs: update API documentation |
style | ์ฝ๋ ํฌ๋งทํ , ์ธ๋ฏธ์ฝ๋ก ๋๋ฝ (๋์ ๋ณ๊ฒฝ X) | style: apply ESLint rules |
refactor | ๋ฆฌํฉํ ๋ง (๊ธฐ๋ฅ ๋ณ๊ฒฝ ์์) | refactor: extract utility functions |
test | ํ ์คํธ ์ฝ๋ ์ถ๊ฐ/์์ | test: add login API tests |
chore | ๋น๋, ์ค์ ๋ณ๊ฒฝ (src ๋ณ๊ฒฝ ์์) | chore: update Webpack config |
perf | ์ฑ๋ฅ ๊ฐ์ | perf: implement lazy loading for images |
์์ธ ํ์ (์ ํ์ฌํญ)
<type>(<scope>): <subject>
<body>
<footer>
์์:
feat(auth): implement JWT-based authentication
- Issue access and refresh tokens
- Store refresh tokens in Redis
- Add token renewal API endpoint
Closes #123
์์ฃผ ํ๋ ์ค์
# โ ํ์
๋๋ฝ
git commit -m "bug fix"
# โ ๋ชจํธํ ์ค๋ช
git commit -m "fix: fix issue"
# โ ํ ์ปค๋ฐ์ ์ฌ๋ฌ ์์
git commit -m "feat: implement login, signup, and password reset"
# โ
๋ช
ํํ๊ณ ๋จ์ผ ์ฑ
์
git commit -m "feat: add form validation to login page"
์ปค๋ฐ ๋ฉ์์ง ์์ฑ ๊ฐ์ด๋๋ผ์ธ
- ์ฒซ ์ค์ 50์ ์ด๋ด - ๊ฐ๊ฒฐํ ์์ฝ
- ํ์ฌํ ์ฌ์ฉ - "added" (X) โ "add" (O)
- ๋ช ๋ นํ ์ด์กฐ - "adds" (X) โ "add" (O)
- ์ฒซ ๊ธ์ ์๋ฌธ์ -
Feat:(X) โfeat:(O) - ๋ง์นจํ ๊ธ์ง -
feat: add feature.(X) โfeat: add feature(O) - ๋ณธ๋ฌธ์ 72์๋ง๋ค ์ค๋ฐ๊ฟ - ๊ฐ๋ ์ฑ ํฅ์
- Why > What - ๋ณ๊ฒฝํ ๋ด์ฉ๋ณด๋ค ๋ณ๊ฒฝํ ์ด์ ๋ฅผ ์ค๋ช
- ์์ด๋ก ์์ฑ - ๋ฆด๋ฆฌ์ฆ ๋ ธํธ ์์ฑ ๋๊ตฌ์์ ํธํ์ฑ์ ์ํด
GitHub Flow ์ํฌํ๋ก์ฐ
๋ธ๋์น ์ ๋ต
main (ํญ์ ๋ฐฐํฌ ๊ฐ๋ฅํ ์ํ)
โโโ feature/login-form
โโโ fix/payment-error
โโโ refactor/user-service
๊ธฐ๋ณธ ๋ธ๋์น
์ ์ ์ฅ์ ์์ฑ ์ ๊ธฐ๋ณธ ๋ธ๋์น๋ main์ ์ฌ์ฉํ๋ค (๊ณผ๊ฑฐ์ master ๋์ ):
# ์ ์ ์ฅ์ ์ด๊ธฐํ ์ main ๋ธ๋์น๋ก ์์
git init -b main
# ๋๋ ๊ธฐ์กด ์ ์ฅ์์์ ๊ธฐ๋ณธ ๋ธ๋์น ๋ณ๊ฒฝ
git branch -m master main
git push -u origin main
# Git ์ ์ญ ์ค์ (๋ชจ๋ ์ ์ ์ฅ์์ ์ ์ฉ)
git config --global init.defaultBranch main
์ฐธ๊ณ : GitHub, GitLab, Bitbucket ๋ฑ ๋๋ถ๋ถ์ Git ํธ์คํ
์๋น์ค๋ 2020๋
๋ถํฐ ๊ธฐ๋ณธ ๋ธ๋์น๋ฅผ main์ผ๋ก ์ฌ์ฉํ๋ค.
๋ธ๋์น ๋ค์ด๋ฐ
# ํ์: <type>/<description>
feature/user-authentication
fix/header-layout-bug
refactor/payment-module
docs/api-documentation
test/user-service
chore/update-dependencies
์์ ํ๋ฆ
# 1. main์์ ์ต์ ์ํ ๋ฐ๊ธฐ
git switch main
git pull origin main
# 2. ์ ๋ธ๋์น ์์ฑ
git switch -c feature/dark-mode
# 3. ์์
ํ ์ปค๋ฐ
git add .
git commit -m "feat: add dark mode toggle button"
# 4. ์๊ฒฉ ๋ธ๋์น์ ํธ์
git push origin feature/dark-mode
# 5. GitHub์์ PR ์์ฑ
gh pr create --title "feat: add dark mode support" --body "..."
# 6. ์ฝ๋ ๋ฆฌ๋ทฐ ํ main์ ๋ณํฉ (GitHub UI ๋๋ CLI)
gh pr merge <PR๋ฒํธ> --squash # ๋๋ --merge, --rebase
# 7. ๋ก์ปฌ main ์
๋ฐ์ดํธ ๋ฐ ๋ธ๋์น ์ญ์
git switch main
git pull origin main
git branch -d feature/dark-mode
PR ๋ณํฉ ์ ๋ต
| ์ ๋ต | ์ค๋ช | ์ธ์ ์ฌ์ฉ |
|---|---|---|
| Squash | ๋ชจ๋ ์ปค๋ฐ์ ํ๋๋ก ํฉ์นจ | ๊ธฐ๋ฅ ๋ธ๋์น (๊ถ์ฅ) |
| Merge | ๋ณํฉ ์ปค๋ฐ ์์ฑ, ํ์คํ ๋ฆฌ ๋ณด์กด | ๋ฆด๋ฆฌ์ค ๋ธ๋์น |
| Rebase | ์ ํ ํ์คํ ๋ฆฌ ์ ์ง, ๋ณํฉ ์ปค๋ฐ X | ๊ฐ๋จํ ๋ณ๊ฒฝ, ๊น๋ํ ํ์คํ ๋ฆฌ |
# Squash (๊ถ์ฅ - ๊ธฐ๋ฅ ๋จ์๋ก ์ปค๋ฐ ์ ๋ฆฌ)
gh pr merge 123 --squash
# Merge (ํ์คํ ๋ฆฌ ๋ณด์กด)
gh pr merge 123 --merge
# Rebase (์ ํ ํ์คํ ๋ฆฌ)
gh pr merge 123 --rebase
Git ํ์คํ ๋ฆฌ ๊ด๋ฆฌ
Rebase
Interactive Rebase (์ปค๋ฐ ์ ๋ฆฌ)
# ์ต๊ทผ 3๊ฐ ์ปค๋ฐ ์์
git rebase -i HEAD~3
# ์๋ํฐ์์ ๋ช
๋ น์ด ์ ํ
# pick โ ์ปค๋ฐ ์ ์ง
# reword โ ์ปค๋ฐ ๋ฉ์์ง ์์
# edit โ ์ปค๋ฐ ์์
# squash โ ์ด์ ์ปค๋ฐ์ ํฉ์นจ
# fixup โ ์ด์ ์ปค๋ฐ์ ํฉ์นจ (๋ฉ์์ง ์ ๊ฑฐ)
# drop โ ์ปค๋ฐ ์ญ์
์์:
# Before
pick a1b2c3d feat: implement login feature
pick d4e5f6g fix: typo in variable name
pick g7h8i9j fix: rename variable for clarity
# After (squash ์ฌ์ฉ)
pick a1b2c3d feat: implement login feature
fixup d4e5f6g fix: typo in variable name
fixup g7h8i9j fix: rename variable for clarity
Rebase onto main (๋ธ๋์น ์ต์ ํ)
# 1. main ์ต์ ํ
git switch main
git pull origin main
# 2. feature ๋ธ๋์น๋ฅผ main ์๋ก rebase
git switch feature/my-feature
git rebase main
# 3. ์ถฉ๋ ๋ฐ์ ์
# - ํ์ผ ์์ ํ
git add .
git rebase --continue
# - rebase ์ทจ์ํ๊ณ ์ถ๋ค๋ฉด
git rebase --abort
Cherry-pick (ํน์ ์ปค๋ฐ๋ง ๊ฐ์ ธ์ค๊ธฐ)
# ๋ค๋ฅธ ๋ธ๋์น์ ์ปค๋ฐ ํ๋๋ง ์ ์ฉ
git cherry-pick <commit-hash>
# ์ฌ๋ฌ ์ปค๋ฐ ์ ์ฉ
git cherry-pick <commit-hash1> <commit-hash2>
# ์ถฉ๋ ๋ฐ์ ์
git add .
git cherry-pick --continue
Commit Amend (๋ง์ง๋ง ์ปค๋ฐ ์์ )
# ๋ง์ง๋ง ์ปค๋ฐ ๋ฉ์์ง๋ง ์์
git commit --amend -m "fix: correct commit message"
# ๋ง์ง๋ง ์ปค๋ฐ์ ํ์ผ ์ถ๊ฐ
git add forgotten-file.ts
git commit --amend --no-edit
# โ ๏ธ ์ฃผ์: ์ด๋ฏธ pushํ ์ปค๋ฐ์ amend ๊ธ์ง (ํ์คํ ๋ฆฌ ๋ณ๊ฒฝ๋จ)
Reset vs Revert
# Reset - ์ปค๋ฐ ์ทจ์ (ํ์คํ ๋ฆฌ ์ญ์ )
git reset --soft HEAD~1 # ์ปค๋ฐ๋ง ์ทจ์, ๋ณ๊ฒฝ์ฌํญ ์ ์ง
git reset --mixed HEAD~1 # ์ปค๋ฐ + staging ์ทจ์, ๋ณ๊ฒฝ์ฌํญ ์ ์ง (๊ธฐ๋ณธ๊ฐ)
git reset --hard HEAD~1 # ์ปค๋ฐ + ๋ณ๊ฒฝ์ฌํญ ๋ชจ๋ ์ญ์ (์ํ!)
# โ ๏ธ pushํ ์ปค๋ฐ์ reset ๊ธ์ง โ revert ์ฌ์ฉ
# Revert - ์ปค๋ฐ์ ๋๋๋ฆฌ๋ ์ ์ปค๋ฐ ์์ฑ (ํ์คํ ๋ฆฌ ๋ณด์กด)
git revert <commit-hash>
git revert HEAD # ๋ง์ง๋ง ์ปค๋ฐ ๋๋๋ฆฌ๊ธฐ
Merge Conflict ํด๊ฒฐ
Conflict ๋ฐ์ ์๋๋ฆฌ์ค
# main์ mergeํ๊ฑฐ๋ rebaseํ ๋ ์ถฉ๋ ๋ฐ์
git merge main
# ๋๋
git rebase main
# Auto-merging src/index.ts
# CONFLICT (content): Merge conflict in src/index.ts
Conflict ํด๊ฒฐ ๊ณผ์
# 1. ์ถฉ๋ ํ์ผ ํ์ธ
git status
# 2. ํ์ผ ์ด์ด์ ์๋ ์์
# <<<<<<< HEAD (ํ์ฌ ๋ธ๋์น)
# ๋ด ๋ณ๊ฒฝ์ฌํญ
# =======
# ์๋ ๋ธ๋์น์ ๋ณ๊ฒฝ์ฌํญ
# >>>>>>> main
# 3. ๋ง์ปค ์ ๊ฑฐํ๊ณ ์ฝ๋ ์์
# 4. ํด๊ฒฐ๋ ํ์ผ staging
git add src/index.ts
# 5. Merge ์๋ฃ
git merge --continue
# ๋๋ Rebase ๊ณ์
git rebase --continue
Conflict ํด๊ฒฐ ์ ๋ต
# ํ์ฌ ๋ธ๋์น ๋ณ๊ฒฝ์ฌํญ ์ฐ์
git restore --ours <file>
# ์๋ ๋ธ๋์น ๋ณ๊ฒฝ์ฌํญ ์ฐ์
git restore --theirs <file>
# merge ์ทจ์
git merge --abort
# rebase ์ทจ์
git rebase --abort
์์ฃผ ์ฌ์ฉํ๋ ๋ช ๋ น์ด
๋ธ๋์น ์์ (git switch)
# ๊ธฐ์กด ๋ธ๋์น๋ก ์ ํ
git switch main
git switch feature/my-feature
# ์ ๋ธ๋์น ์์ฑ + ์ ํ
git switch -c feature/new-feature
# ์ด์ ๋ธ๋์น๋ก ๋์๊ฐ๊ธฐ
git switch -
# ์๊ฒฉ ๋ธ๋์น ์ถ์ ํ๋ฉฐ ์ ํ
git switch -c local-branch origin/remote-branch
์ฐธ๊ณ : Git 2.23+ (2019๋
8์)๋ถํฐ git switch๋ฅผ ์ฌ์ฉํ๋ค. ๊ธฐ์กด git checkout์ ๋ธ๋์น ์ ํ, ํ์ผ ๋ณต์ ๋ฑ ์ฌ๋ฌ ์ญํ ์ ๋ด๋นํด ํผ๋์ ์ผ๊ธฐํ๋ค. git switch๋ ๋ธ๋์น ์ ํ๋ง ๋ด๋นํ๋ค.
ํ์ผ ๋ณต์ (git restore)
# ์์
๋๋ ํ ๋ฆฌ ํ์ผ ๋ณต์ (unstaged ๋ณ๊ฒฝ์ฌํญ ์ทจ์)
git restore <file>
# Staging ์ทจ์ (unstaged๋ก ๋๋๋ฆผ)
git restore --staged <file>
# ์์
๋๋ ํ ๋ฆฌ + Staging ๋ชจ๋ ๋ณต์
git restore --staged --worktree <file>
# ํน์ ์ปค๋ฐ์ ํ์ผ๋ก ๋ณต์
git restore --source=<commit-hash> <file>
์ฐธ๊ณ : git restore๋ ํ์ผ ๋ณต์ ์ ์ฉ ๋ช
๋ น์ด๋ค. ๊ธฐ์กด git checkout -- <file>์ ๋์ฒดํ๋ค.
์ํ ํ์ธ
git status # ๋ณ๊ฒฝ์ฌํญ ํ์ธ
git log --oneline # ์ปค๋ฐ ํ์คํ ๋ฆฌ (ํ ์ค)
git log --graph # ๋ธ๋์น ๊ทธ๋ํ
git diff # ๋ณ๊ฒฝ ๋ด์ฉ ํ์ธ
git diff --staged # staging๋ ๋ณ๊ฒฝ ๋ด์ฉ
git show <commit-hash> # ํน์ ์ปค๋ฐ ์์ธ๋ณด๊ธฐ
Stash (์์ ์ ์ฅ)
git stash # ํ์ฌ ์์
์์ ์ ์ฅ
git stash list # ์ ์ฅ๋ stash ๋ชฉ๋ก
git stash pop # ๋ง์ง๋ง stash ์ ์ฉ + ์ญ์
git stash apply # ๋ง์ง๋ง stash ์ ์ฉ (์ ์ง)
git stash drop # ๋ง์ง๋ง stash ์ญ์
git stash clear # ๋ชจ๋ stash ์ญ์
์๊ฒฉ ์ ์ฅ์
git remote -v # ์๊ฒฉ ์ ์ฅ์ ํ์ธ
git fetch origin # ์๊ฒฉ ๋ณ๊ฒฝ์ฌํญ ๊ฐ์ ธ์ค๊ธฐ (๋ณํฉ X)
git pull origin main # ์๊ฒฉ ๋ณ๊ฒฝ์ฌํญ ๊ฐ์ ธ์ค๊ธฐ + ๋ณํฉ
git push origin main # ๋ก์ปฌ ๋ณ๊ฒฝ์ฌํญ ํธ์
git push -f origin main # ๊ฐ์ ํธ์ (โ ๏ธ ์ํ - ํ ์์
์ ๊ธ์ง)
์ฃผ์ ์ฌํญ (Anti-patterns)
ํ์ฌ ๋๋ ํ ๋ฆฌ์์ ๋ถํ์ํ git -C ์ฌ์ฉ
# โ ํ์ฌ ๋๋ ํ ๋ฆฌ๊ฐ ๋์ ๋ ํฌ์งํ ๋ฆฌ์ธ๋ฐ -C ์ต์
์ฌ์ฉ
git -C /path/to/current/repo log --oneline
# โ
ํ์ฌ ๋๋ ํ ๋ฆฌ์์ ๋ฐ๋ก ์คํ
git log --oneline
ํ์ฌ ๋๋ ํ ๋ฆฌ๊ฐ ์์
๋์ ๋ ํฌ์งํ ๋ฆฌ์ ๋์ผํ๋ฉด git -C ์ต์
์ ๋ถํ์ํ ์ค๋ณต์ด๋ค. ๋ค๋ฅธ ๊ฒฝ๋ก์ ๋ ํฌ์งํ ๋ฆฌ๋ฅผ ๋์์ผ๋ก ํ ๋๋ง ์ฌ์ฉํ๋ค.
๋ณด์ ๋ฐ ์ฃผ์์ฌํญ
์ ๋ ์ปค๋ฐํ๋ฉด ์ ๋๋ ํ์ผ
# .gitignore์ ์ถ๊ฐ
.env # ํ๊ฒฝ ๋ณ์ (API ํค, ๋น๋ฐ๋ฒํธ)
.env.local
*.key # ์ธ์ฆ์ ํค
*.pem
secrets/ # ์ํฌ๋ฆฟ ๋๋ ํ ๋ฆฌ
node_modules/ # ์์กด์ฑ (package.json์ผ๋ก ๊ด๋ฆฌ)
dist/ # ๋น๋ ๊ฒฐ๊ณผ๋ฌผ
.DS_Store # macOS ์์คํ
ํ์ผ
์ค์๋ก ์ปค๋ฐํ ์ํฌ๋ฆฟ ์ ๊ฑฐ
# โ ๏ธ ํ์คํ ๋ฆฌ์์ ์์ ์ญ์ (git filter-branch ๋์ BFG ์ฌ์ฉ)
brew install bfg
bfg --delete-files .env
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# โ ๏ธ ์ฃผ์: ์ด๋ฏธ ํธ์ํ๋ค๋ฉด ์ํฌ๋ฆฟ ์ฆ์ ํ๊ธฐ ํ ์ฌ๋ฐ๊ธ ํ์
Force Push ๊ธ์ง (๊ณต์ ๋ธ๋์น)
# โ main/develop์ force push ์ ๋ ๊ธ์ง
git push -f origin main
# โ
๊ฐ์ธ feature ๋ธ๋์น์์๋ง ํ์ฉ
git push -f origin feature/my-branch
GitHub CLI ํ์ฉ
# PR ์์ฑ
gh pr create --title "feat: add new feature" --body "Description..."
# PR ๋ชฉ๋ก ํ์ธ
gh pr list
# PR ์์ธ๋ณด๊ธฐ
gh pr view 123
# PR ์ฒดํฌ์์ (๋ก์ปฌ์์ ํ
์คํธ)
gh pr checkout 123
# PR ๋ณํฉ
gh pr merge 123 --squash
# Issue ์์ฑ
gh issue create --title "Bug found" --body "Description..."