๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

"git" ํƒœ๊ทธ๋กœ ์—ฐ๊ฒฐ๋œ 3๊ฐœ ๊ฒŒ์‹œ๋ฌผ๊ฐœ์˜ ๊ฒŒ์‹œ๋ฌผ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋ชจ๋“  ํƒœ๊ทธ ๋ณด๊ธฐ

ยท ์•ฝ 4๋ถ„

git-flow#

git-flow ๋Š” Vincent Driessen์˜ ๋ธŒ๋žœ์นญ ๋ชจ๋ธ์„ ์ ์šฉํ•˜์—ฌ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ž‘์—…ํ•  ์ˆ˜์žˆ๋„๋ก ํ•˜๋Š” git์˜ ํ™•์žฅ์ด๋‹ค. ๋” ์•Œ์•„๋ณด๊ธฐ

git-flow vs git-flow-avh#

git-flow ์„ค์น˜ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณด๋ฉด, git-flow-avh๋ฅผ ์„ค์น˜ํ•˜๋ผ๋Š” ๊ฐ€์ด๋“œ๊ฐ€ ๋‚˜์˜ค๋Š”๋ฐ, git-flow ์ €์žฅ์†Œ๊ฐ€ ์žˆ๊ณ , ์ด๊ฒŒ์›๋ณธ์ธ ๊ฒƒ ๊ฐ™์•„์„œ ์•ฝ๊ฐ„์˜ ํ˜ผ๋ž€์ด ์žˆ์—ˆ๋‹ค.

๋‹คํ–‰ํžˆ git-flow-avh์˜ ๊นƒํ—™ ์œ„ํ‚ค์˜ Home๊ณผ FAQ์— ๊ฐ„๋žตํ•œ ์„ค๋ช…์ด์žˆ๋‹ค.

git-flow์—์„œ hooks์™€ filter ๊ตฌํ˜„์ด ํ•„์š”ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์›๋ณธ git-flow์— ๋Œ€ํ•œ ํŒจ์น˜๋ฅผ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. 5๊ฐœ์›”์ด ์ง€๋‚˜๋„, ํŒจ์น˜๊ฐ€ ๊ตฌํ˜„๋˜์ง€ ์•Š์•˜๊ณ  ์šฐ๋ฆฌ๋Š” AVH Edition์„ ๋งŒ๋“œ๋Š” ์ผ์— ์ง‘์ค‘ํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

AVH๋Š” A Virtual Home์ด๋ผ๋Š” ์ž‘์„ฑ์ž์˜ ๊ฐœ์ธ ์›น์‚ฌ์ดํŠธ ์ด๋ฆ„์—์„œ ๋”ฐ์™”๋‹ค๊ณ  ํ•œ๋‹ค. ์ฐธ๊ณ 

AVH Edition์ด git-flow์˜ ๊ธฐ๋ณธ ๊ธฐ๋Šฅ๋“ค์„ ํฌํ•จํ•˜๋ฉด์„œ hooks์™€ filter ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ณ  , cheatsheet ๋ฅผ ํฌํ•จํ•ด์„œ AVH Edition์œผ๋กœ ๊ฐ€์ด๋“œํ•˜๋Š” ๋ฌธ์„œ๊ฐ€ ๋งŽ์•„์„œ AVH Edition์œผ๋กœ ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ–ˆ๋‹ค.

์„ค์น˜ํ•˜๊ธฐ#

Installation ์—์„œ ์šด์˜์ฒด์ œ ๋ณ„ ์„ค์น˜ ๊ฐ€์ด๋“œ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

MacOS ๊ธฐ์ค€์œผ๋กœ๋Š” brew๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ค์น˜ํ•œ๋‹ค.

brew install git-flow-avh

1.7.0 ๋ฒ„์ „์—์„œ git flow init ์‹œ์— ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”๋ฐ, (์ด์Šˆ) ~/.gitflow_export ์— FLAGS_GET_OPT_CMD ํ™˜๊ฒฝ ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ๊ฒƒ์ด ์›์ธ์ด์—ˆ๋‹ค. ๋ฒ„์ „์ด ์—…๋ฐ์ดํŠธ ๋˜๋ฉด์„œ ์ด๋ฅผ ์‚ญ์ œํ•ด์•ผ ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค. ์ฐธ๊ณ 

์‹œ์ž‘ํ•˜๊ธฐ#

๋จผ์ €, git ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

git init hello-git-flow

git ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋กœ ์ด๋™ํ•œ ํ›„, git flow๋ฅผ ์‹œ์ž‘ํ•œ๋‹ค.

cd hello-git-flowgit flow init

CLI์˜ ์งˆ์˜์— ๋”ฐ๋ผ ์ง„ํ–‰ํ•˜์—ฌ ๋ธŒ๋žœ์น˜ ์ปจ๋ฒค์…˜์„ ์ •ํ•œ๋‹ค.

๋ช…๋ น์–ด#

git-flow ๋ช…๋ น์–ด ํ•œ์งค ์š”์•ฝ

git-flow commands

๋Š๋‚€์ #

ํ‰์†Œ ํ•˜๋‚˜์˜ Origin ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋‘๊ณ , main, develop, feature/, fix/ ... ์œผ๋กœ ๋ธŒ๋žœ์นญํ•œ ํ›„, Pull Request -> Merge -> Pull (develop) ๋ฐฉ์‹์˜ workflow๋ฅผ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ git flow์˜ finish ๋ช…๋ น์–ด๊ฐ€ ๋กœ์ปฌ์—์„œ ๋จธ์ง€๋˜๋Š” ๋ฐฉ์‹์ด๋ผ, Pull Request์™€ ํ•จ๊ป˜ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ์ ์ ˆํ•œ์ง€ ๊ณ ๋ฏผ์ด ๋“ค์—ˆ๋‹ค.

๋‹คํ–‰ํžˆ, Stack Overflow์— ๋น„์Šทํ•œ ๊ณ ๋ฏผ์ด์žˆ์—ˆ๋‹ค. ๊ธฐ์กด ์›Œํฌํ”Œ๋กœ์šฐ ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๋ ค๋ฉด, finish ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ , publish -> PR -> Merge -> Pull ์‹์œผ๋กœ ์ง„ํ–‰ํ•˜๋ฉด ๋œ๋‹ค. ์ถ”๊ฐ€์ ์œผ๋กœ git-flow-avh์˜ hooks ๊ธฐ๋Šฅ์„ํ™œ์šฉํ•ด PR ์ž‘์„ฑ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๋˜๋Š”, ํ•˜๋‚˜์˜ Upstream ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋‘๊ณ  forkํ•˜์—ฌ ํ˜‘์—… ๋Œ€์ƒ์ž์˜ ๊ฐœ์ธ Origin ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—์„œ PRํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•˜๋Š” ๋ฐฉ์‹๋„ ์žˆ๋‹ค. ์ฐธ๊ณ 

์ด๋Ÿฌํ•œ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋ฉด, ๊ฐ์ž์˜ Origin repo์—์„œ ๋ถ€๋‹ด์—†์ด ๋‹ค์–‘ํ•œ ์‹คํ—˜๋“ค์„ ํ•ด๋ณผ ์ˆ˜์žˆ๋Š” ์žฅ์ ๋„ ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค.

github-flow-repository-structure

Reference#

git-flow cheatsheet

์šฐ๋ฆฐ Git-flow๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์–ด์š”

ยท ์•ฝ 2๋ถ„

๋นˆ ๋ธŒ๋žœ์น˜ ์ƒ์„ฑํ•˜๊ธฐ#

git checkout --orphan empty-branch
git rm -rf .
# ๋นˆ ์ปค๋ฐ‹ ์ƒ์„ฑํ•˜๊ธฐgit commit --allow-empty -m "Initial commit"

Git Pull ์ „๋žต#

git pull ์„ ๋ณ„๋„ ์˜ต์…˜ ์—†์ด ์‹คํ–‰ํ–ˆ์„ ๋•Œ ๊ฒฝ๊ณ  ๋ฌธ๊ตฌ๊ฐ€ ๋‚˜ํƒ€๋‚ฌ๋‹ค.

warning: Pulling without specifying how to reconcile divergent branches isdiscouraged. You can squelch this message by running one of the followingcommands sometime before your next pull:
git config pull.rebase false  # merge (the default strategy)git config pull.rebase true   # rebasegit config pull.ff only       # fast-forward only
You can replace "git config" with "git config --global" to set a defaultpreference for all repositories. You can also pass --rebase, --no-rebase,or --ff-only on the command line to override the configured default perinvocation.
  • default (merge) : ๋กœ์ปฌ ๋ธŒ๋žœ์น˜์™€ ๋ฆฌ๋ชจํŠธ ๋ธŒ๋žœ์น˜์˜ Head๊ฐ€ ๋‹ค๋ฅธ ์œ„์น˜์— ์žˆ์„ ๋•Œ, pull ๋ฐ›์œผ๋ฉด, Merge ์ปค๋ฐ‹์„ ์ƒ์„ฑํ•จ.

  • rebase : ๋กœ์ปฌ ๋ธŒ๋žœ์น˜์™€ ๋ฆฌ๋ชจํŠธ ๋ธŒ๋žœ์น˜์˜ Head๊ฐ€ ๋‹ค๋ฅธ ์œ„์น˜์— ์žˆ์„ ๋•Œ, pull ๋ฐ›์œผ๋ฉด, ๋ฆฌ๋ชจํŠธ ๋ธŒ๋žœ์น˜๋ฅผ rebase ํ•˜์—ฌ history๋ฅผ ์ •๋ฆฌํ•จ.

  • fast-forward only : fast-forward ๊ด€๊ณ„์— ์žˆ์„ ๋•Œ๋งŒ pull ์„ ํ—ˆ์šฉํ•จ.

2021-02-26-210226-image-0

Git - git-pull Documentation

[GIT] Git pull ์ „๋žต (default, --ff -only, --rebase)

GitHub ํ™˜๊ฒฝ์—์„œ์˜ ์‹ค์ „ Git ๋ ˆ์‹œํ”ผ : NHN Cloud Meetup

Conventional Commit#

Conventional Commits

Git commit ๋ฉ”์„ธ์ง€ ๊ทœ์•ฝโ€Š-โ€ŠConventional Commits

ยท ์•ฝ 3๋ถ„

Merge Options#

Merge#

๊ธฐ๋ณธ์ ์ธ Merge ๋ฐฉ๋ฒ•์œผ๋กœ ํ•˜๋‚˜์˜ ๋ธŒ๋žœ์น˜์˜ ๋ณ€๊ฒฝ ์ด๋ ฅ ์ „์ฒด๋ฅผ ํ•ฉ์น˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

๋‘ ๋ณ€๊ฒฝ ์ด๋ ฅ์„ ๋ณ‘ํ•ฉํ•œ Merge commit์ด ์ƒˆ๋กœ ์ƒ์„ฑ๋œ๋‹ค.

2021-01-03-210103-image-0

Squash and merge#

๋ธŒ๋žœ์น˜ ์ƒ์˜ ๋ชจ๋“  ์ปค๋ฐ‹์„ ํ•˜๋‚˜๋กœ ๋ณ‘ํ•ฉํ•œ ๋‚ด์šฉ์„ ๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜์— ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

PR์— ์žˆ๋Š” commit log๋“ค์„ ํ•œ ๊ฐœ์˜ ์ปค๋ฐ‹์œผ๋กœ ์ถ”๋ ค์„œ main ๋ธŒ๋žœ์น˜์— ๋ณ‘ํ•ฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, 1 PR = 1 commit ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

2021-01-03-210103-image-1

์ฐธ๊ณ ์ž๋ฃŒ#

[Git] Merge ์ดํ•ดํ•˜๊ธฐ (Merge / Squash and Merge / Rebase and Merge)

6. Github์œผ๋กœ ํ˜‘์—…ํ•˜๋Š” ๋ฒ•

GitHub์˜ Merge, Squash and Merge, Rebase and Merge ์ •ํ™•ํžˆ ์ดํ•ดํ•˜๊ธฐ : TOAST Meetup

Rebase and Merge#

๋ธŒ๋žœ์น˜ ์ƒ์˜ ๋ชจ๋“  commit๋“ค์„ ํ•ฉ์น˜์ง€ ์•Š๊ณ  main ๋ธŒ๋žœ์น˜์— ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

2021-01-03-210103-image-2

GitHub๊ณผ GitLab์˜ Squash and merge ์ฐจ์ด#

GitHub#

Github์—์„œ๋Š” PR์— ๋Œ€ํ•œ ๋จธ์ง€ ๋ฐฉ๋ฒ•์„ ๋‹ค์Œ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด ์ œ๊ณตํ•œ๋‹ค.

2021-01-03-210103-image-3

Squash and merge ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ, Merge commit์ด ๋”ฐ๋กœ ์ƒ์„ฑ๋˜์ง€ ์•Š๊ณ , PR ํƒ€์ดํ‹€์„ ์ปค๋ฐ‹ ์ œ๋ชฉ์œผ๋กœ ํ•˜๊ณ , ๋ธŒ๋žœ์น˜์˜ commit log๋“ค์ด ์ปค๋ฐ‹ ๋‚ด์šฉ์œผ๋กœ ์ƒ์„ฑ๋œ๋‹ค.

2021-01-03-210103-image-4

GitLab#

๋ฐ˜๋ฉด, GitLab์—์„œ๋Š” MR์„ ๋จธ์ง€ํ•  ๋•Œ, Squash commits์˜ ์˜ต์…˜์„ ์ฒดํฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š”๋ฐ, GitHub๊ณผ ๋‹ฌ๋ฆฌ ๊ธฐ๋ณธ์ ์œผ๋กœ Merge commit์ด ์ƒ์„ฑ๋˜๋„๋ก ์„ค์ •๋˜์–ด ์žˆ๋‹ค.

2021-01-03-210103-image-5

Merge commit์„ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ธฐ ์œ„ํ•ด์„œ๋Š” Fast-forward merge๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

Fast-forward merge requests

Fast-Forward Merge๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  Squash commits ์˜ต์…˜์„ ์ฒดํฌํ•˜์ง€ ์•Š์œผ๋ฉด, Rebase and Merge ์ฒ˜๋Ÿผ ๋™์ž‘ํ•œ๋‹ค.

Fast-Forward Merge๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  Squash commits ์˜ต์…˜์„ ์ฒดํฌํ•˜๋ฉด Squash and Merge ์ฒ˜๋Ÿผ ๋™์ž‘ํ•œ๋‹ค.

ํ•˜์ง€๋งŒ GitHub์—์„œ ์ž๋™์ ์œผ๋กœ ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€ body์— ๋ธŒ๋žœ์น˜์˜ ์ปค๋ฐ‹ ๋กœ๊ทธ๋ฅผ ๊ธฐ๋กํ•ด์ฃผ๋Š”๋ฐ˜๋ฉด, GitLab์—์„œ๋Š” ์ปค๋ฐ‹ ๋กœ๊ทธ๋ฅผ ๊ธฐ๋กํ•ด์ฃผ์ง€ ์•Š๋Š”๋‹ค. Merge Request์˜ ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด์ด ๋‚ด์šฉ์„ ๋‹ด์„ ์ˆ˜ ์žˆ๊ณ , Modify commit message ๋ฒ„ํŠผ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ง์ ‘ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ๋„๊ฐ€๋Šฅํ•˜๋‹ค.

2021-01-03-210103-image-6

์ฐธ๊ณ ์ž๋ฃŒ#

Merging a pull request

Merge requests