๐ ๋ฐ๋์ ์์์ผ ํ๋ Git
* ์ ๋ฒ ์๊ฐ์ couresra ๊ฐ์ข์์ VCS์ ๋ํด์ ๋ฐฐ์ ์
What is VCS?
* VCS(Version Control System) concepts ๐๐ปโ๏ธ GOAL of VCS = 'To Keep track of Changes made to our files' → when try to manage some changes in IT, it's super important to have detailed historic..
sh-avid-learner.tistory.com
* ์ด์ VCS์ ์ผ์ข ์ธ Git์ ๋ํด์ ์์๋ณด์! (์ถ๊ฐ๋ก GitHub๊น์ง)
(์ฐธ๊ณ ๋ก git์ ๊ทธ๋ฆผ์ผ๋ก ์ดํดํ๋๊ฒ BEST๋ค. ๊ทธ๋ฆฌ๊ณ ์ง์ ํด๋ณด๋๊ฒ ์ฅ๋ก!)
<ํ VCS ์ข ๋ฅ์ Git์ ์ฐจ์ด์ ?>
Git์ ์ผ์ข ์ snapshot์ ์ฐ์ด ๋ณด๊ดํ๋ค
'Instead, Git thinks of its data more like a series of snapshots of a miniature filesystem. With Git, every time you commit, or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored. Git thinks about its data more like a stream of snapshots.'
โถ ์ฆ ํ VCS๋ ๊ธฐ์กด file์ด ์์ผ๋ฉด ์๋ก์ด ๋ณ๊ฒฝ์ฌํญ์ด ์๊ธธ ๋๋ง๋ค ํด๋น ๋ณ๊ฒฝ์ฌํญ์ด ๊ธฐ์กด file์ ๋ฐ์ํ๋, file-based changes๋ก (delta-based Version Control) ์ ์ฅ๋๋๋ฐ / Git์ ์๊ฐ์๊ฐ์, ์ผ์ข ์ snapshot์ ์นด๋ฉ๋ผ๋ก ์ฐ์ด๋ด๋ฏ์ด ๋ณํ๊ฐ ์๊ฒผ์ ๋ ์ ์ฒด์ snapshot ์๊ฐ์ ์ ์ฅํ๋ค.
- ํ VCS(์๋จ)์ git(ํ๋จ)์ ์ฐจ์ด์ (๊ทธ๋ฆผ) -
- ์๊ฒฉ GitHub ์ ์ฅ์์ ํจ๊ป: git ๊ด๋ จ ๋ช ๋ น์ด -
* local ํ๊ฒฝ์์ ์์ ํ๋ git & ๊ทธ๋ฆฌ๊ณ ์๊ฒฉ์ผ๋ก ์ฐ๊ฒฐํ์ฌ ์์ ๊ฐ๋ฅํ GitHub๊น์ง ํฉ์ณ์ - ์๋ก ๊ฐ์ ๊ด๊ณ๋ก ์์๋ณด๋ฉด..
๐ Git์ ์ฝ๋์ ์ฌ๋ฌ ๋ณ๊ฒฝ ์ด๋ ฅ๋ค๊ณผ ๊ธฐ๋ก๋ค์ ์ฝ๊ฒ ์ถ์ ํ๊ณ ํ์ ํ ์ ์๊ธฐ ๋๋ฌธ์ '์ฝ๋ฉ์ ํ์ ๊ธฐ์ ' ์ค ํ๋
๐ ๋ฐ๋ผ์ ์ถ์ & ์ ์ฅ ๊ธฐ๋ฅ ๋๋ฌธ์ ์ฐ๋ฆฌ๋ git์ ํตํด ์ด์ ๊ธฐ๋ก์ผ๋ก ๋์๊ฐ ์๋ ์์ (๋น์ฐํ ์์ ๋ฌผ์ ๋จ๊ธธ ์๋ ์์)
(CLI ๋ฟ ์๋๋ผ GUI๋ก๋ ์ต๊ทผ์ git์ ์ง์ํด์ค - ์ธ์๋ง์ฌ ํธํด์ง ๐ธ ใ ใ )
๐ ์๋ฅผ ๋ค์ด ์ต์ ๋ฒ์ ์ ๋ฌธ์ ๊ฐ ์๊ฒผ์ ๋ ์ด์ ๋ฒ์ ์ผ๋ก ๋ค์ ๋์๊ฐ์ ์์ ์ ์ํํ๊ฑฐ๋ & ๋๋ ์๋ก์ด ๋ฒ์ ์ ๋ค๋ฅด๊ฒ ๋ง๋๋ ๋ฑ, ์ฌ๋ฌ ๋ฒ์ ์ ๋ง๋ค์ด (์ผ์ข ์ branch๋ก ๋์ดํด) ๊ด๋ฆฌํ ์ ์๋ GIT
โชGit์ ์ฌ์ฉํด GitHub์ ์ด์ฉํ๋ ๋ฐฉ๋ฒ์ ์์ ์๋ ๋ ๊ทธ๋ฆผ์ ๋ชจ๋ ์ ๋ฆฌ๋จ! ์์ ๊น.๋. ๐โซ
๐ local์ด remote๋ก ์ฌ๋ฆฌ๋ ๋ฐฉ๋ฒ / ๋ฐ๋๋ก remote์์ local๋ก ๊ฐ์ ธ์ค๋ ๋ ๋ฐฉํฅ ๋ชจ๋ ๊ณต๋ถํด ๋ณด์ ๐
๐ ๋จผ์ git init์ผ๋ก git ์ ์ฅ์ ๋ง๋ค๊ธฐ ๐
→ ์ผ๋จ ํด๋น ์์น์ 'git์ผ๋ก remoteํ๊ฒ ๊ด๋ฆฌํ๊ฒ ๋ค'๋ผ๊ณ ์ ์ธํ๋ git ๋ช ๋ น์ด์ด๋ค.
(+) .gitignore ์์ฑ - git์ผ๋ก ์๊ฒฉ ์์น์ ์๋ค๊ฐ๋ค ํ๊ธฐ ์ด๋ ค์ด file๋ค์ด๋ git์ผ๋ก publicํ๊ฒ ๊ด๋ฆฌ๋ฅผ ํ๋ฉด ์๋๋, ๋ณด์์์ ๋ฌธ์ ๊ฐ ์์๋งํ ๋ชจ๋ file๋ค์ด๋ ๋ณ๊ฒฝ์ฌํญ๋ค์ gitignore file์ ์์ฑํด ํด๋น ํ์ผ์ ์ ์ฅํ๋ค.
โ GitHub → local repo๋ก ๊ฐ์ ธ์ค๊ธฐ
1> ๋จผ์ ํด๋น repo๋ฅผ ๋ด GitHub ๊ณ์ ์ repo๋ก forking
2> fork๋ ๋ด ๊ณ์ ์ repo ์ฃผ์๋ฅผ ๋ณต์ฌํด git clone ๋ค์ ๋ถ์ฌ ๋ด local๋ก ๊ฐ์ ธ์ด
(์ฌ๊ธฐ์ git remote -v๋ฅผ ์ฌ์ฉํด ์๊ฒฉ์ผ๋ก ์ฐ๊ฒฐ์ด ๋ branch ์ด๋ฆ๊ณผ ์ํ๋ฅผ ์ ์ ์์)
โ ์ฌ๊ธฐ์! git clone & git pull & git fetch & git merge ? ์ฐจ์ด์ โ
๐ git pull์ ํ์ฌ ๋ด๊ฐ local์์ ์์ ํ๊ณ ์๋ '๋์ค์' ์๊ฒฉ repo์ ์๋ก์ด ๋ด์ฉ์ local๋ก ๊ฐ์ ธ์ค๊ณ ์ถ์ ๋ ์ฌ์ฉ
โ๏ธ git clone์ ์ ์ด์ ์ฒ์ ์์ ํ ๋ ์ด๋ฐ์ ์๊ฒฉ repo ๋ด์ฉ ๋ชจ๋๋ฅผ ๊ทธ๋๋ก ๊ฐ์ ธ์ฌ ๋ ์ฌ์ฉ
(git clone ์ฒ์์๋ง! ์ดํ ์๊ฒฉ repo update๋ ๋๋ง๋ค git pull๋ก ์กฐ๊ธ์ฉ ์กฐ๊ธ์ฉ local๋ก ๊ฐ์ ธ์ค๋ ์๋๋ฆฌ์ค๊ฐ BEST)
๐ค git pull = git fetch + git merge
- ์ญ์ ๊ทธ๋ฆผ์ ํตํด ํ์ธํ๋ฉด - (master branch๊ฐ ์๋๋ผ 'main' branch์
๋๋ค. ์ธ์ข
์ฐจ๋ณ์ฉ์ด ๊ธ์ง๋จ) -
→ git fetch๋ฅผ ํตํด ํ์ฌ ๋ด๊ฐ ์์ ํ๊ณ ์๋ branch๋ฅผ trackingํ๊ณ ์๋ ์๊ฒฉ branch๋ก๋ง fetchํ๋ค
→ ๊ทธ๋ฆฌ๊ณ git merge ๊ณผ์ ์ ํตํด remote branch์ ๋ณ๊ฒฝ ์ฌํญ์ ํ์ฌ ๋ด local branch๋ก ๊ฐ์ ธ์ฌ ์ ์๋ค.
→ ๊ทธ๋ฆฌ๊ณ ์ด git fetch + git merge ๊ณผ์ ์ ํฉ์น ๊ฒ 'git pull' ๊ณผ์ !
โฆ ์ฌ๊ธฐ์ git fetchํ ๋ค ํ์ฌ local branch์ ๋ณ๊ฒฝ์ฌํญ์ด tracking๋์ด ์๋ค๋ฉด, git mergeํ๋ ๊ณผ์ ์์ conflict! ์ถฉ๋ ๋ฐ์ (์ฃผ์!) โฆ
Q. ๊ทธ๋ ๋ค๋ฉด, ๋๋์ฒด ์, git pull ํ๋ฒ์ ํ๋ฉด ๋ ๊ฑธ, ์ git fetch + git merge ์ด๋ ๊ฒ ๋๋ ๊ฒ์ผ๊น?
A. for ํ์ !
→ ํ ํ๋ก์ ํธ์ ์ฌ๋ฌ developer๋ค์ด ๋ค์ํ branch์ ์์ ์ ํ๊ณ main branch์ mergingํ๋ ๊ณผ์ ์ ๊ฑฐ์น ํ ๋ฐ, ์ฌ๊ธฐ์ ํ developer๊ฐ ์ธ๋ถ์์ fetchingํด์ ๊ฐ์ ธ์จ ์์ ๋ค์ ๋ฐ๋ก mergingํ๋ ์์ ๊น์ง ๊ฑฐ์น๋ค๋ฉด, ๋ค๋ฅธ developer๋ค์ ๋์ ์์ด ๋ฐ๋ก local branch์ ๋ณ๊ฒฝ์ด ๋ฐ์ํ๋ค. ๊ฐ์ด ํ์ ํ๋ ๊ณผ์ ์์ ์ผ์ข ์ developer๋ค๋ผ๋ฆฌ ์ผ๊ด๋ consensus๊ฐ ๋ฐ์ํด์ผ ํ๊ณ , ๋์๋ฅผ ์ป์ผ๋ฉด git merge ์งํ, ์๋๋ฉด ์ทจ์ํ๋ ์ ์ฐจ๋ฅผ ๋ฐ๊ฒ ๋๋ค!
3> branch ํ์ธ(git branch) + ์ฌ์ฉํ branch working directory๋ก ๊ฐ์ ธ์ค๊ณ (git checkout) ์์ ์์!
→ ์ผ๋จ ์ฌ๋ฌ branch๊ฐ ์๋ ์ง ํ์ธํ๋ค. default๋ก๋ main์ด๋ ํ์๋ ๋ค๋ฅธ branch๊ฐ ์๋ ์ง git branch๋ก ํ์ธ
(git branch -al์ด๋ฉด ์๊ฒฉ ํฌํจ ๋ชจ๋ branch ์ข
๋ฅ ์ถ๋ ฅ)
→ ๋ด๊ฐ ์ํ๋ ๋ค๋ฅธ branch์์ ์์ ์ ํ๊ณ ์ถ๋ค๋ฉด git checkout --branchname์ ํตํด ์์ branch๋ฅผ switching!
โก ๋ด working directory์์ ์์ ํ ๊ฒฐ๊ณผ๋ฌผ์ GitHub์ผ๋ก ๋ด๋ณด๋ด๊ธฐ (git clone ๊ฒฐ๊ณผ ๋ด local์์ ๋ง๋ค์ด์ง localrepo)
1> working directory์์ ์ฌ๋ฌ ํ์ผ๋ค์ ์์ ํ๋ ๋ฑ ์์ ์ ์๋ฃํ์๋ค๋ฉด staging area์ ์ฌ๋ฆฌ๊ธฐ ์ํด git add
→ ๋ณ๊ฒฝ์ฌํญ์ด ์ด์ git์ ์ํด ์ถ์ ๋๊ธฐ ์์ (git add ./์ ์ฌ์ฉํ๋ฉด ๋ชจ๋ file์ด staging area๋ก ์ฌ๋ผ๊ฐ๋๋ฐ ์ด๋ ์ํํ๋ฏ๋ก ์ ํํ commitํ ๋์์ด ๋๋ file๋ค๋ง git์ ๊ธฐ๋ก๋๊ฒ๋ git add ๋ค์ ์ผ๋ถ ํ์ผ๋ค๋ง ์ฌ๋ฆฐ๋ค)
2> git add๋ staging area์์ ์ต์ข ์ ์ผ๋ก git commit -m 'commit message'๋ฅผ ์ฌ์ฉํด local repo์ ์ฌ๋ฆฌ๊ธฐ (์ปค๋ฐ ๋ฉ์์ง ํ์)
(โป git status๋ฅผ ํตํด ์ด๋ค file๋ค์ด working directory, staging area, localrepo์ ์๋ ์ง ์ฌ๋ฌ ์ํ๋ค์ ํ ๋์ ์ ์ ์์)
Q. ์ staging area๋ฅผ ๋ฐ๋ก ๋ฌ์ git add & git commit ์ด๋ ๊ฒ ๋ ๊ณผ์ ์ ๊ฑฐ์น๊ฒ ํ๋ ๊ฑธ๊น์?
A. (by Stackoverflow)
-1- 'staging helps you split up one large change into multiple commits' : ๋ก์ปฌ์ ์ฌ๋ฌ ๋ณ๊ฒฝ๋ค์ด ์์๋๋ฐ ์ด ๋ณ๊ฒฝ๋ค์ ๊ฐ๋ณ์ ์ผ๋ก ๊ตฌ๋ถํ์ฌ ๋ฐ๋ก ์๊ฒฉ repo์ ์ฌ๋ฆฌ๊ณ , ๋ค๋ฅธ ํ์๋ค์ด ๊ฐ ๋ณ๊ฒฝ๋ค์ ์ ์ฐจ์ ์ผ๋ก ์ฝ๊ฒ ์ดํดํ ์ ์๊ฒ ํ๊ณ ์ถ์ ๋ - ๋ณ๊ฒฝ๋ค ๋ถ๋ถ๋ถ๋ถ๋ง๋ค git commit์ ์ฌ๋ฆด ์ ์๋ค๋ ์ฅ์ ์ด ์กด์ฌ!
-2- 'staging helps in reviewing changes' : staging ๋จ๊ณ์ ์๋ file๋ค์ git diff๋ฅผ ์ฌ์ฉํด (git commit ํ๊ธฐ ์ด์ ) ์ฌ๋ฌ ๋ณํ๋ค์ ์ดํด๋ณผ ์ ์๋ค. ๋ฐ๋ผ์ git์ ์ฌ์ฉํด ์ฐ๋ฆฌ๋ ์ต์ข ์ ์ผ๋ก ์ด๋ค ๋ถ๋ถ์ ๋ฌธ์ ๊ฐ ์๊ณ ์ด๋ค ๋ณํ๊ฐ ์๋ ์ง ์ธ์ฌํ๊ฒ ํ์ธํ ์ ์๋ค๋ ์ฅ์ ์ด ์์!
-3- 'staging helps when a merge has conflicts' : merge๊ฐ ๋ฐ์ํ๊ฒ ๋๋ฉด staging area์ ๋ด์ฉ์ด ๋ฐ์๋๋ค (branch ํฉ๋ณ!)
-4- 'staging helps you keep extra local files hanging around' : ํผ์ ์ถ๊ฐ์ ์ผ๋ก local file์ ์์ ํ๊ณ ๋ฐ์ํ๊ณ ์ถ์ ๋ ํด๋น branch์ ์๋ ์์ ์ ๋ฐ๋ก commitํ๊ฑฐ๋ ์ผ๋ถ๋ง staging area์ ์ฌ๋ ค ๋๋ง ๋๋ฆ๋๋ก ๊ด๋ฆฌ๊ฐ ๊ฐ๋ฅํ๋ค!
-5- 'staging helps you sneak in small changes' : ํฐ ์์ ์ ํ๋ค๊ณ ๊ฐ์ ํ ๋, ์ผ๋ถ ๋ณํ๋ง ๋ฐ์์ ํด์ผ ํ๋ค๋ฉด ์ฝ๊ฒ staging area์ ์๋ ์ผ๋ถ๋ง commitํด์ ์ฌ๋ฆด ์ ์๋ค. ์ด๋ staging area๊ฐ ์กด์ฌํ๊ธฐ ๋๋ฌธ์ ์ผ๋ถ๋ฅผ ๊ณจ๋ผ์ commitํ ์ ์๋ค๋ ์ !
(+) git log๋ฅผ ํตํด ๋ณ๊ฒฝ์ฌํญ์ ํ์ธํ ์ ์์ (์ฌ๋ฌ commit ๊ธฐ๋ก ํ์ธ ๊ฐ๋ฅ)
3> git push๋ก ๋ด GitHub ๊ณ์ remote repo์ ์ฌ๋ฆฌ๊ธฐ
→ ex) git push origin main - origin์ด๋ผ๋ ์๊ฒฉ branch์ ๋ด local ํ๊ฒฝ์์ ์์ ํ main branch๊ฐ ์ฌ๋ผ๊ฐ
4> GitHub ์ฌ์ดํธ์์ forked๋ ๋ด repo์ pull request ๋ฒํผ ํด๋ฆญ! (main repo ๊ด๋ฆฌ์์ ์น์ธ์ด ๋๋ฉด ๋ฐ์)
→ ์ด์ ์ค์ main hosting GitHub repo์ ๋ด๊ฐ ์ง์ ๋ณ๊ฒฝํ ๋ถ๋ถ์ด commit message์ ํจ๊ป ์ค์ PR๋ก ๋ฐ์๋๋ค
* ๊ฐ๋จํ๊ฒ git & github ๊ธฐ์ด์ ๋ํด์ ์์๋ด ๐ (๊ผญ ๊ธฐ์ตํ ๋ถ๋ถ!) *
* ๊ทธ๋ฆผ ์ถ์ฒ) https://velog.io/@kbs5665/Git-Workflowpair-programming
* ์ถ์ฒ - git ์ค๋ช ๊ณต์ docu) https://www.git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F
* ์ถ์ฒ) fetch vs. pull - https://medium.com/@sabbirhossain_70520/git-fetch-vs-git-pull-691823ed4239
* ์ถ์ฒ) https://www.daleseo.com/git-init/
* ์ถ์ฒ) https://kimcoder.tistory.com/288
* ์ถ์ฒ) https://stackoverflow.com/questions/49228209/whats-the-use-of-the-staging-area-in-git
'IT knowledge > VCS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
What is VCS? (0) | 2022.03.31 |
---|
๋๊ธ