Git
Git Workflow
1 . ์ ํ๋ก์ ํธ์ ๊ฒฝ์ฐ, ๋ก์ปฌ ์ปดํจํฐ์์ ์์ ํ๊ธฐ ์ํด clone ํด์ค
git clone <project url>
2 . ๋ชจ๋ ๊ธฐ๋ฅ ๋ถ๊ธฐ๋ ํ๋ก์ ํธ์ ์ต์ ์ฝ๋ ์ํ์์ ์์ฑ
git checkout main
git fetch origin
git reset --hard origin/main
ํน์
git pull origin main
3 . ์ ๊ธฐ๋ฅ์ ๊ฐ๋ฐํ๊ธฐ์ ์์ ๊ฒฉ๋ฆฌ๋ ์์ ๋ธ๋์น๋ฅผ ๋ง๋ค๊ณ , ํด๋น ๋ธ๋์น๋ก ์ฒดํฌ์์ ํ๋ค.
git checkout -b <branchname>
ํน์
git branch <branchname>
git checkout <branchname>
4 . issue ํ์ธ ๋ฐ ํด๋น ์์ ์งํ
git add <file1> <file2> ...
git commit -m "commit message"
5 . ์๊ฒฉ branch์ ํธ์
git push -u origin <branchname>
6 . Github ์ ์ฅ์์์ Compare & Pull Request ๋ฒํผ์ ํตํด Pull Request ์์ฑ
7 . PR ์์ฒญ์ ๊ฒํ ์๊ฐ ์ฝ๋ ๋ณ๊ฒฝ๋ด์ญ์ ํ์ธํ๊ณ Merge ์ฌ๋ถ๋ฅผ ๊ฒฐ์
8 . Merge ์ดํ ๋๊ธฐํ ๋ฐ branch๋ฅผ ์ ๊ฑฐ
โจ reference
Github Project Management
Github๋ฅผ ์ด์ฉํด์ Project Management ํ๋ ๋ฐฉ๋ฒ ๋ฐ ์ ์ฒด์ ์ธ ํ๋ก์ธ์ค. (issue ๊ด๋ฆฌ, ์ผ์ ๊ด๋ฆฌ, ์ฝ๋๋ฆฌ๋ทฐ, ๋ฒ๊ทธ ๋ฆฌํฌํธ ๋ฑ)
โจ 1 . ์ ์ฒด ํ๋ก์ฐ
Issue ๋ฐ๊ธ
Issue ์์
Pull Request Code Review ์งํ
Issue ๋ฐ์
โจ 2 . Issue
Issue ๋ฐํ
๋ชจ๋ ํ๋ ๋ด์ญ์ ์๋ฏธํ๋ค. ์ด๋ฅผ ํ ๋ฉด ์๋ก ์ถ๊ฐ๋ ๊ธฐ๋ฅ, ๊ฐ์ ํด์ผํ ๊ธฐ๋ฅ, ๋ฒ๊ทธ ๋ฑ์ด ์๋ค
Issue template
Issue๋ฅผ ๋ฑ๋กํ ํ ํ๋ฆฟ์ ์ค์ ํ ์ ์๋ค
https://github.com/cheese10yun/github-project-management#issue-template
Issue ์์
Assignees : ํด๋ฌ ์์ ์ ๋ด๋น์
Labels : ํด๋น ์์ ์ ์ฑ๊ฒฉ
Milestone : ํด๋น ์์ ์ด ์ํ ํํธ
Milestone :
Sprint๋ฅผ ๊ด๋ฆฌํด์ฃผ๋ ๋๊ตฌ๋ก, Due Date๋ฅผ ์ค์ ํ ํ ํด๋น ๊ธฐ๊ฐ ๋ํ ์ํํ Issue๋ค์ ๋ฑ๋กํด ๋๊ณ ์งํ ์ํฉ์ ํ์ธํ ์ ์๋ค
โจ 3 . Pull Request
PUll Request ์์ฑ
Github ํญ์์ New Pull Request ๋ฒํผ์ ํด๋ฆญs
PR ์์
resolved #์ด์๋๋ฒ (https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
๋ฆฌ๋ทฐ์ด ์ง์
โจ 4 . Code Review
โจ 5 . Wiki
ํ๋ก์ ํธ์ ๋ฌธ์๋ฅผ ๊ด๋ฆฌ
โจ 6 . Project
๋ฐ๊ธ๋ ๋ง์ ์ด์๋ค์ ํ๋์ ๋ณด๊ธฐ ์ํ UI๋ฅผ ์ ๊ณต
โจ reference
Git Style Guide
โจ 1. Branches
Perform work in a feature branch.
main
feature/\*
1.1 main
> ์ ํ์ผ๋ก ์ถ์๋ ์ ์๋ ๋ธ๋์น
> ๋ฒ์ ๊ด๋ฆฌ๊ฐ ํ์๋๋ ๊ฒฝ์ฐ master/1.0.0 ์ด๋ฌํ ํ์์ผ๋ก ๋ธ๋์น๋ฅผ ์์ฑํฉ๋๋ค.
1.2 feature/\*
> ๊ธฐ๋ฅ์ ๊ฐ๋ฐํ๋ ๋ธ๋์น
1.3 ์์ธ ๊ท์น
main ๋ธ๋์น๋ feature/\* ๋ธ๋์น์ ์ํด merge ๋์ด ์์ ๋์ผ ํฉ๋๋ค.
feature ๋ธ๋์น์์ main ๋ธ๋์น์ merge ํ ๋,
๋ฐ๋์ main ๋ธ๋์น์ ์๋ ๋ด์ฉ์ pull ํด์ผ ํฉ๋๋ค.
(์ถฉ๋์ ๋ก์ปฌ์์ ์์ ํ๊ธฐ ์ํด์)
โจ 2. Commits
Writing good commit messages
2.1 ๊ตฌ์กฐ
`issue(์ต์ ex MP-3) type(์ต์ ): subject(ํ์)
body(์ต์ )`
issue: ๊ด๋ จ๋ ์ด์ ๋ฒํธ๋ฅผ ์์ฑํฉ๋๋ค.
type: ์ด๋ค ์๋๋ก ์ปค๋ฐํ๋์ง๋ฅผ type์ ๋ช ์ํฉ๋๋ค.
subject: ์ต๋ 50๊ธ์๊ฐ ๋์ง ์๋๋ก ํ๊ณ ๋ง์นจํ๋ ์ฐ์ง ์์ต๋๋ค.
์๋ฌธ์ผ๋ก ํ๊ธฐํ๋ ๊ฒฝ์ฐ ๋์ฌ(์ํ)์ ๊ฐ์ฅ ์์ ๋๊ณ ์ฒซ๊ธ์๋ ๋๋ฌธ์๋ก ํ๊ธฐํฉ๋๋ค.
body: ๊ธด ์ค๋ช ์ด ํ์ํ ๊ฒฝ์ฐ์ ์์ฑํฉ๋๋ค.
ํ์ค์ ์ต๋ 75๊ธ์๋ฅผ ๋๊ธฐ์ง ์๋๋ก ํฉ๋๋ค.
์ด๋ป๊ฒ ํ๋์ง๊ฐ ์๋๋ผ, ๋ฌด์์ ์ ํ๋์ง ์์ฑํฉ๋๋ค.
2.2 Type
Type์ ํญ์ ์๋ฌธ ์๋ฌธ์๋ก ์์ฑํฉ๋๋ค.
feat : ์๋ก์ด ๊ธฐ๋ฅ ์ถ๊ฐ
fix : ๋ฒ๊ทธ ์์
docs : ๋ฌธ์์ ์์
style : UI๋ฅผ ์ถ๊ฐ/๋ณ๊ฒฝ ํ๊ฑฐ๋ ์คํ์ผ ๊ด๋ จ ์์
refactor : ์ฝ๋๋ฅผ ๋ฆฌํํ ๋ง
test : Test ๊ด๋ จํ ์ฝ๋์ ์ถ๊ฐ, ์์
chore : ๊ธฐ๋ฅ/ํ ์คํธ, ๋ฌธ์, ์คํ์ผ, ๋ฆฌํฉํ ๋ง ์ธ์ ๋ฐฐํฌ, ๋น๋์ ๊ฐ์ด ํ๋ก์ ํธ์ ๊ธฐํ ์์ ๋ค์ ๋ํด ์ถ๊ฐ/์์
โจ 3. Pull Request (Merge)
3.1 ๊ท์น
main ๋ธ๋์น๋ก์ merge๋ feature/\* ๋ธ๋์น์ ์ํด์๋ง ๊ฐ๋ฅํฉ๋๋ค.
merge์ merge๊ฐ ๋๋ ๋ธ๋์น์์ pull์ ๋จผ์ ํ๊ณ ์ถฉ๋์ด ์๋ค๋ฉด ํด๊ฒฐํ ๋ค merge๋ฅผ ํด์ผ ํฉ๋๋ค.
merge๋ github pull request์์ ์งํํฉ๋๋ค.
โจ reference
์ฐ์ต ์์ : https://hankkuu.tistory.com/87
Git rebase & merge
Git delete branch
โจ local
โจ remote
git push origin --delete {branch-name}
Git์ ์๋ชป ์ฌ๋ผ๊ฐ ํ์ผ ์ญ์
โจ ์๊ฒฉ ์ ์ฅ์์์ ํ์ผ ์ญ์
git rm [File Name]
git rm --cached [File Name]
์์
git rm --cached .DS_Store
git rm --cached -r .idea/
โจ .gitignore ์ค์
์ ์ฌ์ดํธ๋ฅผ ์ฐธ๊ณ ํ์ฌ gitignore ์ค์
โจ ์๊ฒฉ ์ ์ฅ์์ ์ ์ฉ
git commit -m "chore : Delete .idea/"
git push origin main
โจ reference
Git add, git commit, git push ๋๋๋ฆฌ๊ธฐ
โจ git add ์ทจ์
ํ์ผ ์ํ๋ฅผ Unstage๋ก ๋ณ๊ฒฝ
git add *
git status
git reset HEAD [File Name]
git status
โจ git commit ์ทจ์
git log
// ๋ฐฉ๋ฒ 1 :
// commit์ ์ทจ์
// ํด๋น ํ์ผ๋ค์ staged ์ํ๋ก ์ํน ๋๋ ํฐ๋ฆฌ์ ๋ณด์กด
git reset --soft HEAD^
// ๋ฐฉ๋ฒ 2 :
// commit์ ์ทจ์
// ํด๋น ํ์ผ๋ค์ unstaged ์ํ๋ก ์ํน ๋๋ ํฐ๋ฆฌ์ ๋ณด์กด
git reset mixed HEAD^
git reset HEAD^
git reset HEAD~2 // ๋ง์ง๋ง 2๊ฐ์ commit์ ์ทจ์
// ๋ฐฉ๋ฒ 3
// commit์ ์ทจ์
// ํด๋น ํ์ผ๋ค์ unstaged ์ํ๋ก ์ํน ๋๋ ํฐ๋ฆฌ์์ ์ญ์
git reset --hard HEAD^
โจ git commit message ๋ณ๊ฒฝ
git commit --amend
โจ reset ์ต์
soft : index ๋ณด์กด(addํ ์ํ, staged ์ํ), ์ํน ๋๋ ํฐ๋ฆฌ์ ํ์ผ ๋ณด์กด. ์ฆ ๋ชจ๋ ๋ณด์กด.
mixed : index ์ทจ์(addํ๊ธฐ ์ ์ํ, unstaged ์ํ), ์ํน ๋๋ ํฐ๋ฆฌ์ ํ์ผ ๋ณด์กด (๊ธฐ๋ณธ ์ต์ )
hard : index ์ทจ์(addํ๊ธฐ ์ ์ํ, unstaged ์ํ), ์ํน ๋๋ ํฐ๋ฆฌ์ ํ์ผ ์ญ์ . ์ฆ ๋ชจ๋ ์ทจ์.
์ํน ๋๋ ํฐ๋ฆฌ๋ฅผ ์๊ฒฉ ์ ์ฅ์์ ๋ง์ง๋ง commit ์ํ๋ก ๋๋๋ฆฌ๊ณ ์ถ์ ๊ฒฝ์ฐ
git reset --hard HEAD
โจ git push ์ทจ์
์ด ๋ช ๋ น์ ์ฌ์ฉํ๋ฉด ์์ ์ local์ ๋ด์ฉ์ remote์ ๊ฐ์ ๋ก ๋ฎ์ด์ฐ๊ธฐ๋ฅผ ํ๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์ฃผ์ํด์ผ ํจ.
๋๋์๊ฐ commit ์ดํ์ ๋ชจ๋ commit ์ ๋ณด๊ฐ ์ฌ๋ผ์ง๊ธฐ ๋๋ฌธ์ ์ฃผ์.
ํนํ, ํ์ ํ๋ก์ ํธ์์๋ ๋๊ธฐํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์์ผ๋ฏ๋ก ํ์๊ณผ ์์ ํ ์งํํ๋ ๊ฒ์ด ์ข์
์ํน ๋๋ ํฐ๋ฆฌ์์ commit์ ๋๋๋ฆผ
// 1.1 :
// ๊ฐ์ฅ ์ต๊ทผ์ commit์ ์ทจ์ํ๊ณ ์ํน ๋๋ ํฐ๋ฆฌ ๋๋๋ฆผ
git reset HEAD^
// 1.2 :
// ์ํ๋ ์์ ์ผ๋ก ์ํน ๋๋ ํฐ๋ฆฌ ๋๋๋ฆผ
// 1.2.1
git reflog
// or
git log -g
//1.2.2
git reset HEAD@{number}
// or
git reset [commit id]
๋๋๋ ค์ง ์ํ์์ ๋ค์ commmit
git commit -m "chore : Revert commit"
์๊ฒฉ ์ ์ฅ์์ ๊ฐ์ ๋ก push
git push origin [Branch Name] -f
// or
git push origin +[Branch Name]
โจ reference
Git commit ๋๋๋ฆฌ
Git sub module
Git stash
Git remote repository ๋ณ๊ฒฝ
Git fork and PR
Git ๊ด๊ณ ์๋ ์ปค๋ฐ ๋ณํฉ ๊ฑฐ๋ถ
Git rebase
Git branch ์ ๋ต
Github repo ๊ด๋ฆฌ
sub module
sub tree
๋ฃจํธ ํ๋ก์ ํธ ๋ด๋ถ์์ ๊ฐ๊ฐ git clone git clone
ref
Etc
โจ command line์์ ๋ฉ์ธ์ง์ ์ค๋ช
๊ฐ์ด ์ฐ๊ธฐ
git commit -m "Title" -m "Description ..........";
โจ github submodule ์ฌ์ฉ
โจ reference
Last updated