๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Environment·Tool/IntelliJ IDEA

IntelliJ์—์„œ Git/GitHub ์‚ฌ์šฉํ•˜๊ธฐ - ๊ธฐ์กด ํ”„๋กœ์ ํŠธ ์—ฐ๋™ํ•˜๊ธฐ

by Leica 2020. 2. 17.
๋ฐ˜์‘ํ˜•

GitHub์— ์ƒˆ๋กœ์šด remote repository๋ฅผ ๋งŒ๋“ค๊ณ  ๊ธฐ์กด IntelliJ ํ”„๋กœ์ ํŠธ(๋ชจ๋“ˆ)์„ ์—ฐ๋™ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๋‹ค๋ฃฌ๋‹ค.

IntelliJ๋Š” 2019.3 ๋ฒ„์ „์„ ๊ธฐ์ค€์œผ๋กœ ํ•œ๋‹ค.

 

๊ณผ์ •์€ ๋‹ค์Œ ์ˆœ์„œ๋กœ ์ง„ํ–‰๋œ๋‹ค.

  1. GitHub remote repository ์ƒ์„ฑํ•˜๊ธฐ
  2. IntelliJ์— GitHub ๊ณ„์ • ๋“ฑ๋กํ•˜๊ธฐ
  3. IntelliJ์— remote repository ๋“ฑ๋กํ•˜๊ธฐ
  4. ๊ธฐ์กด ํ”„๋กœ์ ํŠธ(๋ชจ๋“ˆ)๋กœ Git local repository๋ฅผ ๋งŒ๋“ค๊ณ  Commit, Push

 

IntelliJ์—์„œ Git์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด PC์— Git์„ ์„ค์น˜ํ•˜๊ณ  Git ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ์„ IntelliJ์— ๋“ฑ๋กํ•ด์•ผ ํ•œ๋‹ค.

์ด๊ฒŒ ๋˜์–ด์žˆ์ง€ ์•Š์œผ๋ฉด ๋‹ค์Œ ๋‚ด์šฉ์„ ์ฐธ๊ณ ํ•ด์„œ ์„ ํ–‰ํ•ด๋‘์–ด์•ผ ํ•œ๋‹ค.


Git ํ”Œ๋Ÿฌ๊ทธ์ธ ํ™•์ธ

Settings - Plugins์—์„œ ์„ค์น˜ ์—ฌ๋ถ€์™€ ํ™œ์„ฑํ™” ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

Settings

Installed ํƒญ์„ ํด๋ฆญํ•˜๊ณ  git์„ ๊ฒ€์ƒ‰ํ•˜์—ฌ Git, GitHub ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€, ํ™œ์„ฑํ™” ์ƒํƒœ์ธ์ง€ ํ™•์ธํ•œ๋‹ค.
Disable ๋ฒ„ํŠผ์ด ๋ณด์ด๋ฉด ํ™œ์„ฑํ™”๋œ ์ƒํƒœ์ด๋‹ค.

IntelliJ IDEA 2019.3์—๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์„ค์น˜, ํ™œ์„ฑํ™”๋˜์–ด์žˆ๋‹ค.

 

Git ๋‹ค์šด๋กœ๋“œ ๋ฐ ์„ค์น˜

- ์œˆ๋„์šฐ์šฉ Git ๋‹ค์šด๋กœ๋“œ ๋ฐ ์„ค์น˜ํ•˜๊ธฐ - ์„ค์น˜ ์˜ต์…˜์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์„ค๋ช… ํฌํ•จ

 

IntelliJ์— Git ์‹คํ–‰ํŒŒ์ผ ๊ฒฝ๋กœ ์ง€์ •

Settings - Version Control - Git์„ ํด๋ฆญํ•œ๋‹ค.

Path to Git executable์— Git ์‹คํ–‰ํŒŒ์ผ์„ ์ง€์ •ํ•˜๊ณ  [Test]๋ฅผ ํด๋ฆญํ•˜์—ฌ ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜๋Š”์ง€ ํ…Œ์ŠคํŠธํ•ด๋ณธ๋‹ค.

Git ์‹คํ–‰ํŒŒ์ผ git.exe๋Š” Git ์„ค์น˜ ๋””๋ ‰ํ† ๋ฆฌ\bin ํ•˜์œ„์— ์žˆ๋‹ค.

 

Git ์‹คํ–‰ํŒŒ์ผ์ด ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰ ํ…Œ์ŠคํŠธ๋œ ๋ชจ์Šต


1. GitHub Remote Repository ์ƒ์„ฑํ•˜๊ธฐ

Git์€ ๋กœ์ปฌ repository๊ฐ€ ์žˆ์–ด์„œ ์›๊ฒฉ repository๊ฐ€ ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•œ๊ฑด ์•„๋‹ˆ์ง€๋งŒ Git ์‚ฌ์šฉ์ž๋“ค์€ ๋Œ€๋ถ€๋ถ„ ์›๊ฒฉ repository๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. GitHub์—์„œ ๋ฌด๋ฃŒ ์›๊ฒฉ repository๋ฅผ ์ œ๊ณตํ•˜๋ฏ€๋กœ ์ด๋ฅผ ์ด์šฉํ•˜๋„๋ก ํ•˜๊ฒ ๋‹ค.

 

GitHub ๊ณ„์ •์ด ์—†์œผ๋ฉด ์ƒ์„ฑํ•˜๊ณ  https://github.com/new๋กœ ์ ‘์†ํ•ด์„œ GitHub repository๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

 

 

  • Repository name : ์ €์žฅ์†Œ ์ด๋ฆ„์„ ์ง€์ •ํ•œ๋‹ค. Url์— ์‚ฌ์šฉ๋˜๋ฏ€๋กœ ๊ฐ„๋‹จํ•œ๊ฒŒ ์ข‹๋‹ค.
  • Description : ์ €์žฅ์†Œ ์„ค๋ช…์„ ๊ธฐ์ž…ํ•œ๋‹ค.
  • Public / Private : ๊ณต๊ฐœ ๋ฒ”์œ„๋ฅผ ์„ค์ •ํ•œ๋‹ค. Public์€ ๋ˆ„๊ตฌ์—๊ฒŒ๋‚˜ ๊ณต๊ฐœ๋˜๊ณ  Private์€ ๊ณต๊ฐœ๋˜์ง€ ์•Š๋Š”๋‹ค. ๋‘ ์˜ต์…˜ ๋‹ค ๊ถŒํ•œ์ด ์žˆ๋Š” ์‚ฌ์šฉ์ž๋งŒ ์ €์žฅ์†Œ๋กœ Commitํ•  ์ˆ˜ ์žˆ๋‹ค.
  • Initialize this repository with a README : ์ฒดํฌํ•˜๋ฉด ์ž๋™์œผ๋กœ ๋กœ์ปฌ repository์™€ README.md ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค. IntelliJ ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ local repository๋กœ ๋งŒ๋“ค๊ฒƒ์ด๋ฏ€๋กœ ์ฒดํฌํ•˜์ง€ ์•Š๋Š”๋‹ค.

 

โ— Initialize this repository with a README ์˜ต์…˜
์ด ์˜ต์…˜์— ์ฒดํฌํ•ด์„œ ์ €์žฅ์†Œ๋ฅผ ์ƒ์„ฑํ•˜๋ฉด ์ด ์ €์žฅ์†Œ์— push/pull ์‹œ๋„ ์‹œ rejected/refusing์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.
๋”ฐ๋ผ์„œ ์ƒˆ๋กœ ์ €์žฅ์†Œ๋ฅผ ๋งŒ๋“ค๊ณ  ๊ธฐ์กด ํ”„๋กœ์ ํŠธ๋ฅผ pushํ•˜๋ ค๋ฉด ์ด ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

 

ํ•„์š” ํ•ญ๋ชฉ์„ ์ž‘์„ฑํ•˜๊ณ  Create repository๋ฅผ ํด๋ฆญํ•ด์„œ repository๋ฅผ ๋งŒ๋“ ๋‹ค.

 

์ €์žฅ์†Œ ์ƒ์„ฑ ์™„๋ฃŒ

์ด๋ ‡๊ฒŒ ์ €์žฅ์†Œ๋ฅผ ๋งŒ๋“ค๊ณ ๋‚˜๋ฉด Initialize this repository with a README ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ์œ„์™€ ๊ฐ™์ด ๋กœ์ปฌ ์ €์žฅ์†Œ๋ฅผ ๋งŒ๋“ค๊ณ  ์ดˆ๊ธฐํ™”ํ•˜๋Š” ๊ฒƒ์— ๋Œ€ํ•œ ๊ฐ€์ด๋“œ๊ฐ€ ํ‘œ์‹œ๋œ๋‹ค.

๊ธฐ์กด์˜ IntelliJ ํ”„๋กœ์ ํŠธ๋ฅผ ๋กœ์ปฌ ์ €์žฅ์†Œ๋กœ ๋งŒ๋“ค๊ณ  ์ด ์ƒˆ๋กœ ๋งŒ๋“  ์›๊ฒฉ ์ €์žฅ์†Œ์— pushํ•  ๊ฒƒ์ด๋ฏ€๋กœ ์•„๋ž˜ ๊ณผ์ •์„ ๋”ฐ๋ฅธ๋‹ค.

 

2. IntelliJ์— GitHub ๊ณ„์ • ๋“ฑ๋กํ•˜๊ธฐ

Settings ์ฐฝ์—์„œ Version Control - GitHub์„ ์„ ํƒํ•˜๊ณ  ์šฐ์ธก [+] ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด์„œ Log In to GitHub ์ฐฝ์„ ๋„์šด๋‹ค.

๊ณ„์ • ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  [Log In]์„ ํด๋ฆญํ•œ๋‹ค.

 

[OK]๋ฅผ ํด๋ฆญํ•˜์—ฌ ๊ณ„์ • ๋“ฑ๋ก์„ ์™„๋ฃŒํ•œ๋‹ค.

์ฐธ๊ณ ๋กœ ์šฐ์ธก [V] ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์„ ํƒํ•œ ๊ณ„์ •์„ default๋กœ ์‚ฌ์šฉํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

3. IntelliJ์— Remote Repository ๋“ฑ๋กํ•˜๊ธฐ

VCS - Git - Remotes...๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

[+]์„ ํด๋ฆญํ•œ๋‹ค.

 

์ƒˆ๋กœ ๋งŒ๋“  GitHub remote repository url์„ ์ž…๋ ฅํ•˜๊ณ  [OK]๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

4. ๊ธฐ์กด ๋ชจ๋“ˆ๋กœ Git Local Repository ๋งŒ๋“ค๊ณ  Commit, Push

์ƒˆ๋กœ ๋งŒ๋“  remote repository์™€ ์—ฐ๋™ํ•  ๊ธฐ์กด ๋ชจ๋“ˆ์„ Git local repository๋กœ ๋งŒ๋“ ๋‹ค.

 

VCS - Import into Version Control - Create Git Repository...๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

๋ชจ๋“ˆ์„ ์„ ํƒํ•˜๊ณ  [OK]๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

Settings - Version Control์— ๋กœ์ปฌ ์ €์žฅ์†Œ๋กœ ๋งŒ๋“  ๋ชจ๋“ˆ์ด ์ž๋™์œผ๋กœ ์ถ”๊ฐ€๋œ๋‹ค.

 

Local repository๋กœ ๋งŒ๋“ค๊ณ ๋‚˜๋ฉด Project ๋ทฐ์—์„œ ํŒŒ์ผ๋ช…์ด ๋ถ‰์€์ƒ‰์œผ๋กœ ํ‘œ์‹œ๋œ๋‹ค.

 

๋ชจ๋“ˆ ์•ˆ์˜ ๋””๋ ‰ํ† ๋ฆฌ/ํŒŒ์ผ์„ ์„ ํƒํ•˜๊ณ  VCS - Git - Add๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

Addํ•˜๊ณ ๋‚˜๋ฉด ํŒŒ์ผ๋ช…์ด ์ดˆ๋ก์ƒ‰์œผ๋กœ ํ‘œ์‹œ๋œ๋‹ค. VCS - Commit์„ ํด๋ฆญํ•œ๋‹ค.

 

Commit Message๋ฅผ ์ž…๋ ฅํ•˜๊ณ  [Commit and Push...]๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

[Commit]์ด ์•„๋‹Œ [Commit and Push]๋ฅผ ์„ ํƒํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— Commit์ด ์™„๋ฃŒ๋˜๋ฉด Push ์ฐฝ์ด ๋ฐ”๋กœ ๋œฌ๋‹ค.

[Push]๋ฅผ ํด๋ฆญํ•œ๋‹ค.

 

Version Control ๋ทฐ์˜ Console ํƒญ์—์„œ IntelliJ๊ฐ€ Git bash๋กœ ์‹ค์ œ ์–ด๋–ค ๋ช…๋ น์„ ๋‚ ๋ฆฌ๊ณ  ์–ด๋–ค ์‘๋‹ต์„ ๋ฐ›์•˜๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

์œ„์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋˜๋ฉด ์ •์ƒ์ ์œผ๋กœ Push๊ฐ€ ์™„๋ฃŒ๋œ ๊ฒƒ์ด๋‹ค.

 

์ด๋ ‡๊ฒŒ GitHub repository์— ๊ธฐ์กด ๋ชจ๋“ˆ์ด ์ •์ƒ์ ์œผ๋กœ ์—ฐ๋™๋˜์—ˆ๋‹ค.

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€