IntelliJ์์ Git์ ์ฌ์ฉํ๋ ๊ธฐ์ด์ ์ธ ๋ฐฉ๋ฒ์ ์ค๋ช
ํ๋ ๊ธ์
๋๋ค.
IntelliJ IDEA 2021.3(Ultimate) ๋ฒ์ ์ ๊ธฐ์ค์ผ๋ก ์์ฑ๋์์ต๋๋ค.
์ด ๊ธ์์๋ Git ๋ช
๋ น์ด๋ ์ฌ์ฉํ์ง ์๊ณ , IntelliJ์์ GUI๋ก ์ ๊ณตํ๋ ๊ธฐ๋ฅ๋ง ์ฌ์ฉํฉ๋๋ค.
โ๏ธGit ์ค์น
https://git-scm.com/downloads ์์ ๊ฐ์์ ์ด์์ฒด์ ์ ๋ง๋ ์ค์นํ์ผ์ ๋ค์ด๋ก๋ ํ ์ค์นํด์ค๋ค.
* Standalone Installer(์ค์น ๋ฒ์ ), Portable(๋ฌด์ค์น ๋ฒ์ )์ด ์๋๋ฐ ํน๋ณํ ์ด์ ๊ฐ ์์ผ๋ฉด Standalone Installer๋ฅผ ์ถ์ฒ
* Next๋ง ๋๋ฌ์ ์ค์น๋ฅผ ์๋ฃํด๋ ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉํ๋๋ฐ ๋ฌธ์ ์๋ค.
* ์๋ ๋งํฌ์ ๊ฐ ์ด์์ฒด์ ๋ณ ์ค์น๋ฐฉ๋ฒ ๋ฐ ์ค์น Step๋ณ ์์ธํ ์ค๋ช ์ด ์ ๋์์์ผ๋ ํ์ํ ์ฌ๋์ ์ฐธ๊ณ
https://www.lainyzine.com/ko/article/a-summary-of-git-installation-methods-by-operating-system/
โ๏ธGit ์ฌ์ฉ์ ์ ๋ณด ์ค์
์๋ ๋ช ๋ น์ด๋ฅผ ์๋์ฐ cmd์ฐฝ์ด๋ git bash๋ IntelliJ Terminal ์ค ์๋ฌด๋ฐ์๋ ์ ๋ ฅํด์ค๋ค.
์ด ๊ณผ์ ์ ์๋ตํ๋ฉด ๋์ค์ commit ํ์ ๋ History์ ๋ณด์ด๋ ์ด๋ฆ๊ณผ ๋ฉ์ผ ์ฃผ์๊ฐ ์๋ํ์ง ์์ ๊ฐ์ผ๋ก ๋์จ๋ค.
git config --global user.name "์ฌ์ฉ์ ์ด๋ฆ"
git config --global user.email "์ฌ์ฉ์ ์ด๋ฉ์ผ ์ฃผ์"
โ๏ธIntelliJ GitHub ์ฐ๋
โท GitHub ๊ฐ์ (https://github.com/)
โท IntelliJ ํ๋ก์ ํธ ์์ฑ (์๋ฌด ํ๋ก์ ํธ๋ ์๊ด์์)
โท IntelliJ์ GitHub ์ฐ๋
- IntelliJ ํ๋ฉด ์๋จ ๋ฉ๋ด์์ File -> Settigs... ํด๋ฆญ
- ์คํ๋ ํ์ ์์ Version Control -> GitHub ํด๋ฆญ
- +๋ฒํผ ํด๋ฆญ -> Log In via GitHub... ํด๋ฆญ
- ์คํ๋ JetBrain ์นํ์ด์ง์์ Authorize in GitHub ๋ฒํผ ํด๋ฆญ
- ์คํ๋ GitHub ์นํ์ด์ง์์ ๋ก๊ทธ์ธ
- IntelliJ ํ์ ์์ OK ๋ฒํผ ํด๋ฆญ
โ๏ธGitHub Repository ์์ฑ ๋ฐ ์์ค ์ฌ๋ฆฌ๊ธฐ
โท IntelliJ ํ๋ฉด ์๋จ ๋ฉ๋ด์์ Git -> GitHub -> Share Project on GitHub ํด๋ฆญ
โท ์คํ๋ ํ์ ์์ Share ๋ฒํผ ํด๋ฆญ
โท ์คํ๋ ํ์ ์์ Add ๋ฒํผ ํด๋ฆญ
์ฌ๊ธฐ๊น์ง ์งํํ๊ณ GitHub์ ๋ค์ด๊ฐ๋ณด๋ฉด ์๋ก์ด Repository๊ฐ ์์ฑ๋์ด ์๊ณ , ๋ด๊ฐ ์์ฑํ ํ๋ก์ ํธ ์์ค๊ฐ ์ฌ๋ผ๊ฐ ์๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
โ๏ธGit Repository์์ ์์ค Local๋ก ๋ด๋ ค๋ฐ๊ธฐ
์ฐ์ต์ผ์ ํด๋ณด๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์ด ๋ถ๋ถ์ ๊ทธ๋ฅ ๊ฑด๋ ๋ฐ์ด๋ ์๊ด์๋ค.
โท IntelliJ ํ๋ฉด ์๋จ ๋ฉ๋ด์์ File -> Close Project ํด๋ฆญ
โท Local์์ ์๊น ์์ฑํ๋ ํ๋ก์ ํธ ํด๋๋ฅผ ์ญ์
โท ์คํ๋ ํ์ ์์ Get from VCS ๋ฒํผ ํด๋ฆญ
โท URL ์ ๋ ฅ ํ๊ณ , Directory ์ง์ ํ Clone ๋ฒํผ ํด๋ฆญ
* URL์ GitHub ์นํ์ด์ง์์ ์ด์ ์ ์์ฑํ๋ Repository๋ฅผ ํด๋ฆญํ๋ฉด ๋ธ๋ผ์ฐ์ ์ ์ฃผ์ํ์์ค์์ ํ์ธ ๊ฐ๋ฅ
โ๏ธGit Branch ์ ๋ต
Git Branch๋ฅผ ์์ฑํ๊ณ , ๊ด๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ๊ฐ ํ์ฌ/ํ๋ง๋ค ๋ค๋ฅด๋ค.
์ด ๊ธ์์๋ ์ด 4๊ฐ์ Branch๋ฅผ ์์ฑํด์ ์ฐ์ตํด๋ณผ ์์ ์ด๋ค.
โท master(์์ฉ์๋ฒ์ ๋ฐฐํฌ๋ ๋ฒ์ ),
โท develop(๊ฐ๋ฐ์๋ฒ์ ๋ฐฐํฌ๋ ๋ฒ์ )
โท feature1(๊ธฐ๋ฅ1 ๊ฐ๋ฐ์ค์ธ Branch)
โท feature2(๊ธฐ๋ฅ2 ๊ฐ๋ฐ์ค์ธ Branch)
โ๏ธBranch ํ์ธํ๊ธฐ, Branch ์์ฑํ๊ธฐ
Git Repository๋ฅผ ์์ฑํ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก master Branch๊ฐ ์์ฑ๋์ด ์๋ค.
์ข์ธก ํ๋จ์ Git ํญ์ ํด๋ฆญํ๋ฉด Branch ๋ชฉ๋ก๊ณผ Git History๋ฅผ ๋ณผ ์ ์๊ณ ,
์ฐ์ธก ํ๋จ์ master๋ผ๊ณ ๋์ด์๋ ๋ถ๋ถ์ ํด๋ฆญํด๋ Branch ๋ชฉ๋ก์ ๋ณผ ์ ์๋ค.
์ฐ์ธก ํ๋จ์ master๋ ํ์ฌ Branch์ ์ด๋ฆ์ ์๋ฏธํ๋ค.
์ข์ธก ํ๋จ์ +๋ฒํผ์ ํด๋ฆญํ๊ฑฐ๋ ์ฐ์ธก ํ๋จ์ ํ์ฌ Branch๋ช ์ ํด๋ฆญํ๋ฉด ๋์ค๋ ํ์ ์ฐฝ์์ + New Branch๋ฅผ ํด๋ฆญํ๋ฉด ์๋ก์ด Branch๋ฅผ ์์ฑํ ์ ์๋ค. develop Branch๋ฅผ ์์ฑํด๋ณด๋๋ก ํ์.
Branch๋ฅผ ํ์ธํด๋ณด๋ฉด Local์๋ง ์๊ฒผ๊ณ , Remote์๋ ์์ฑ๋์ง ์์๋ค.
์ฐ์ธก ์๋จ์ Push ๋ฒํผ(๋ น์ ํ์ดํ ๋ชจ์ ๋ฒํผ)์ ํด๋ฆญํด์ Push๋ฅผ ์๋ฃํ๋ฉด Remote์๋ develop Branch๊ฐ ์์ฑ๋๋ค.
โ๏ธGit Index(Staging Area)์ ์ถ๊ฐํ๊ธฐ
Git์ Index(Staging Area)์ ์๋ ํ์ผ๋ง commit ํ ์ ์๋ค.
์๋ก์ด ํ์ผ์ ์์ฑํด๋ณด๋ฉด Add File to Git์ด๋ผ๋ ํ์ธ์ฐฝ์ด ์ถ๋ ฅ๋๋ค.
Add ๋ฒํผ์ ํด๋ฆญํ๋ฉด Index์ ์ถ๊ฐ๋๊ณ , ํ์ผ๋ช ์ด ๋ น์์ผ๋ก ๋ฐ๋๋ค.
Cancel ๋ฒํผ์ ํด๋ฆญํ๋ฉด Index์ ์ถ๊ฐ๋์ง ์๊ณ , ํ์ผ๋ช ์ด ๋นจ๊ฐ์์ผ๋ก ๋ฐ๋๋ค.
๊ธฐ์กด์ ์๋ ํ์ผ์ ๋ด์ฉ์ ์์ ํ๋ฉด Index์ ์ถ๊ฐ๋๊ณ , ํ์ผ๋ช ์ด ํ๋์์ผ๋ก ๋ฐ๋๋ค.
Index์ ์ถ๊ฐ๋์ง ์์ ํ์ผ์ ๋ค์ Index์ ์ถ๊ฐํ๋ ค๋ฉด ์ข์ธก์ ํ์ผ๋ชฉ๋ก ํธ๋ฆฌ์์ ํ์ผ ์ฐํด๋ฆญ -> Git -> Add๋ฅผ ํด๋ฆญํ๋ฉด ๋๋ค.
โ๏ธCommit / Push
Commit ๋ฒํผ(์ฐ์ธก ์๋จ์ ๋ น์ ์ฒดํฌ๋ชจ์์ ๋ฒํผ)์ ํด๋ฆญํ๋ฉด ์ข์ธก ์๋จ์ Commit ๊ฐ๋ฅํ ํ์ผ ๋ชฉ๋ก์ด ํ์๋๋ค.
Changed ํ์์ ์๋ ํ์ผ์ด Git Index์ ์ถ๊ฐ๋ ํ์ผ์ด๊ณ ,
Unversioned Files ํ์์ ์๋ ํ์ผ์ Git Index์ ์ถ๊ฐ๋์ง ์์ ํ์ผ์ด๋ค.
Commit ํ ํ์ผ์ ์ฒดํฌํ๊ณ , ํ์ผ ๋ชฉ๋ก ์๋์ Commit ๋ฉ์์ง๋ฅผ ์์ฑํ ํ ๊ทธ ๋ฐ์ ์๋ Commit ๋ฒํผ์ ํด๋ฆญํ๋ฉด Local Branch์ Commit์ด ์๋ฃ๋๋ค.
๊ทธ ์์ Commit and Push... ๋ฒํผ์ ํด๋ฆญํ๋ฉด Remote Branch๊น์ง ํ๋ฐฉ์ ์ฌ๋ผ๊ฐ๋ค.
Local Branch๋ฅผ ๊ตณ์ด ํ์ฉํ์ง ์๋๋ค๋ฉด Commit and Push...๊ฐ ๋ ํธํ ๋ฐฉ๋ฒ์ด๋ค.
์ฐ์ธก ์๋จ์ Push ๋ฒํผ(๋ น์ ํ์ดํ ๋ชจ์ ๋ฒํผ)์ ํด๋ฆญํ๋ฉด Index์ ์ถ๊ฐ๋ ํ์ผ์ด Remote Branch๋ก ์ฌ๋ผ๊ฐ๋ค.
โป IntelliJ์์๋ Git Index์ ์ถ๊ฐ๋์ง ์์ ํ์ผ๋ ์ฒดํฌํ๊ณ Commit ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์๋์ผ๋ก Git Index์ ์ถ๊ฐ ํ Local Branch์ Commit ํ๋ค.
โ๏ธHistory ํ์ธํ๊ธฐ
History๋ฅผ ํ์ธํด๋ณด๋ฉด Commit๋ง ํ์ ๋๋ Branch๋ช ์ด develop์ด๋ผ๊ณ ๋ง ๋์ด์๊ณ , Push๊น์ง ์๋ฃํ๋ฉด origin & develop์ผ๋ก ๋ณ๊ฒฝ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
History ํ์ค์ ํด๋ฆญํ๋ฉด ์ฐ์ธก์ ๋ณ๊ฒฝ๋ ํ์ผ ๋ชฉ๋ก์ด ์ถ๋ ฅ๋๋ค.
ํ์ผ์ ๋๋ธํด๋ฆญํ๋ฉด ์ด์ ๊ณผ ๋น๊ตํด์ ์ด๋ค ๋ถ๋ถ์ด ๋ฌ๋ผ์ก๋์ง ์์ธํ ๋ณด์ฌ์ค๋ค.
โ๏ธCheckout / Merge
ํ์ฌ๊น์ง์ ๋ณ๊ฒฝ์ฌํญ์ develop Branch์๋ง ์ ์ฉ๋์ด ์๋ค.
master Branch์๋ ์ ์ฉํ๋ ค๋ฉด ์ผ๋จ master Branch๋ก ์ด๋ํด์ผํ๋ค.
Branch ์ด๋์ Checkout์ด๋ผ๊ณ ํ๋ค.
Branch ๋ชฉ๋ก์์ master๋ฅผ ์ฐํด๋ฆญ ๋๋ ํด๋ฆญ ํ checkout์ ํด๋ฆญํ๋ฉด develop Branch์์ master Branch๋ก ์ด๋๋๋ค.
โป Local Branch๋ก Checkout ํ๋ Remote Branch๋ก Checkout ํ๋ ๋๊ฐ์ด Local Branch๋ก Checkout์ด ๋๊ธฐ ๋๋ฌธ์ checkout ํ ๋๋ Local๊ณผ Remote๋ฅผ ์ ๊ฒฝ์ธ ํ์๋ ์๋ค.
Branch ๋ชฉ๋ก์์ develop์ ์ฐํด๋ฆญ ๋๋ ํด๋ฆญ ํ Merge 'develop' into 'master'๋ฅผ ํด๋ฆญํ๋ฉด master์ Local Branch์๋ง develop Branch์ ๋ณ๊ฒฝ๋ด์ฉ์ด ๋ฐ์๋๋ค.
Push๊น์ง ์๋ฃํ๋ฉด Remote Branch๊น์ง ๋ฐ์๋๋ค.
โป Local Branch๋ฅผ Mergeํ๋ฉด Commitํ ๋ด์ฉ๋ง ๋ฐ์๋๊ณ , Remote Branch๋ฅผ Mergeํ๋ฉด Push๊น์ง ์๋ฃ๋ ๋ด์ฉ์ด ๋ฐ์๋๋ค.
โ๏ธFetch
Fetch๋ ์ ์ฒด Remote Branch์ ๋ณ๊ฒฝ๋ด์ฉ์ด ์๋์ง ํ์ธํ๋ ๊ธฐ๋ฅ์ด๋ค.
ํ ์คํธ๋ฅผ ์ํด develop Branch๋ก Checkoutํ ํ feature1 Branch๋ฅผ ์์ฑํ๊ณ , Push ํด์ค๋ค.
๋ค์ develop Branch๋ก Checkoutํ ํ feature2 Branch๋ฅผ ์ํ๊ณ , Push ํด์ค๋ค.
โป ์๋ก ์์ฑ๋ Branch๋ ํ์ฌ Checkout๋ Branch๋ฅผ ๊ธฐ์ค์ผ๋ก ์์ฑ๋๋ ๊ฒ์์ ๊ธฐ์ตํด์ผ ํ๋ค.
Github ์นํ์ด์ง์์ feature1/feature2 Branch์ ์์ค๋ฅผ ์ง์ ์์ ํ๊ณ , Commit ํ๋ค.
๊ทธ๋ฆฌ๊ณ IntelliJ ํ๋ฉด ์๋จ ๋ฉ๋ด์์ Git -> Fetch๋ฅผ ํด๋ฆญํ๋ค.
feature1/feature2 Remote Branch์ History๋ Github ์นํ์ด์ง์์ ์์ ๋ ๋ด์ญ์ด ์ถ๊ฐ๋์ด ์๊ณ ,
feature1/feature2 Local Branch ์ฐ์ธก์๋ ์๋์ชฝ์ผ๋ก ํฅํ ํ๋์ ํ์ดํ ์์ด์ฝ์ด ์๊ธด ๊ฒ์ ํ์ธํ ์ ์๋ค.
๋ด๋ ค๋ฐ์ ์์ค๊ฐ ์๋ค๋ ์๋ฏธ์ด๋ค.
Fetch๋ ๋ณ๊ฒฝ์ฌํญ์ด ์๋ Remote Branch์ History๋ฅผ ์ ๋ฐ์ดํธ ํด์ฃผ๊ณ , Local Branch๋ ๋ด๋ ค๋ฐ์ ์์ค๊ฐ ์๋ค๊ณ ์๋ ค์ฃผ๋ ๊ธฐ๋ฅ์ด๋ผ๊ณ ๋ณผ ์ ์๋ค.
โ๏ธUpdate Project...
Update Project...๋ IntelliJ ํ๋ฉด ์ฐ์ธก ์๋จ์ ํ๋์์ ์๋์ชฝ์ผ๋ก ํฅํ ํ์ดํ ๋ฒํผ์ด๋ค.
ํ์ฌ Checkout๋ Branch๋ฅผ Fetch ํ๊ณ , Remote Branch๋ฅผ Local Branch๋ก Merge ํด์ฃผ๋ ๊ธฐ๋ฅ์ด๋ค.
โ๏ธConflict ํด๊ฒฐ
Push, Merge, Update Project ๋ฑ์ ํ ๋ ๊ฐ์ ํ์ผ์ ๋์ผํ ๋ถ๋ถ์ ์๋ก ๋ค๋ฅด๊ฒ ์์ ๋์ด ์์ผ๋ฉด Conflict๊ฐ ๋ฐ์ํ๋ค.
Conflict๊ฐ ๋ฐ์ํ๋ฉด ์๋์ ๊ฐ์ ํ์ ์ด ํธ์ถ๋๋๋ฐ ์ผ์ชฝ๊ณผ ์ค๋ฅธ์ชฝ์ ์ฐธ๊ณ ํด์ ๊ฐ์ด๋ฐ๋ฅผ ์ ๋นํ๊ฒ ์์ ํด์ฃผ๋ฉด ๊ฐ์ด๋ฐ์ ์์ค๋ก ์ ์ฉ์ด ๋๋ค.
โ๏ธCommit ์ทจ์
Git History์์ ์์ง Push๋์ง ์์ ์ด๋ ฅ์ ์ฐํด๋ฆญ ํ ํ Undo Commit...์ ํด๋ฆญํ๋ฉด Commit ์ทจ์๊ฐ ๊ฐ๋ฅํ๋ค.
โ๏ธRollback
์์ ๋ ๋ด์ฉ์ ๊ฐ์ฅ ์ต๊ทผ History๋ก ๋๋๋ฆด ์ ์๋ค.
ํ์ผ์์ค์์ ์ฐํด๋ฆญ -> Git -> Rollback์ ํด๋ฆญํ์ฌ ํ ์๋ ์๊ณ , ํ์ผ๋ชฉ๋ก์์ ์ฌ๋ฌ๊ฐ๋ฅผ ํ๊บผ๋ฒ์ ์ ํํ๊ณ ์ฐํด๋ฆญ -> Git -> Rollback์ ํด๋ฆญํด์๋ ํ ์ ์๋ค.
โ๏ธSmart Checkout / Force Checkout
Local์์ ์์ค๋ฅผ ์์ ํ๊ณ , Commitํ์ง ์์ ์ํ์์ ๋ค๋ฅธ Branch๋ก Checkoutํ ๋ ์ถฉ๋์ด ๋ฐ์ํ๋ฉด ์๋์ ๊ฐ์ ํ์ ์ฐฝ์ด ๋์ฌ ์๋ ์๋ค. Force Checkout์ ํด๋ฆญํ๋ฉด Local์์์ ์์ ๋ ๋ด์ฉ์ ๋ ๋ ค๋ฒ๋ฆฌ๋ ๊ฒ์ด๊ณ , Smart Checkout์ Local์์์ ๋ณ๊ฒฝ ๋ด์ฉ์ Git Index์ ๋ณด๊ดํ๋ ๊ฒ์ด๋ค.