๊ด€๋ฆฌ ๋ฉ”๋‰ด

Unfazedโ—๏ธ๐ŸŽฏ

git fetch, git pull ๋ณธ๋ฌธ

Git, GitHub

git fetch, git pull

9taetae9 2025. 1. 10. 20:31
728x90

๋ฆฌ๋ชจํŠธ ์ €์žฅ์†Œ

๊นƒํ—ˆ๋ธŒ ๋ ˆํฌ์ง€ํ† ๋ฆฌ(๋ฆฌ๋ชจํŠธ ์ €์žฅ์†Œ)๋ฅผ Clone ํ•  ๋•Œ git clone ๋ช…๋ น์€ ์ž๋™์œผ๋กœ ๋ฆฌ๋ชจํŠธ ์ €์žฅ์†Œ๋ฅผ "origin"์ด๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ์ถ”๊ฐ€ํ•œ๋‹ค.

๋ฆฌ๋ชจํŠธ ์ €์žฅ์†Œ๋Š” git remote ๋ช…๋ น์œผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. (-v ์˜ต์…˜์œผ๋กœ fetch์™€ push URL ํ™•์ธ ๊ฐ€๋Šฅ)

๋ฆฌ๋ชจํŠธ ์ €์žฅ์†Œ ๊ธฐ๋ณธ ํ™•์ธ
URL ์ •๋ณด ํฌํ•จํ•˜์—ฌ ํ™•์ธ

 

๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ์ž‘์—… ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๋ฆฌ๋ชจํŠธ ์ €์žฅ์†Œ(main branch)์— ํ‘ธ์‰ฌํ–ˆ์„ ๋•Œ ๋กœ์ปฌ ์ €์žฅ์†Œ๋Š” ์ด๋ฅผ ๋ฐ”๋กœ ์ธ์ง€ํ•˜์ง€ ๋ชปํ•œ๋‹ค.

๋กœ์ปฌ ์ €์žฅ์†Œ์—์„œ ๋ฆฌ๋ชจํŠธ ์ €์žฅ์†Œ์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ธ์ง€ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” fetch๋ฅผ ํ•ด์•ผ๋œ๋‹ค.

 

git fetch

  • ๋กœ์ปฌ ์ €์žฅ์†Œ์— ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ œ์™ธํ•˜๊ณ  ์›๊ฒฉ ์ €์žฅ์†Œ(remote repository)์—์„œ ๋ฐ์ดํ„ฐ(๋ธŒ๋žœ์น˜, ํƒœ๊ทธ ๋“ฑ)์„ ๊ฐ€์ ธ์˜ด
  • ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋Š” ๋กœ์ปฌ์˜ .git ๋””๋ ‰ํ† ๋ฆฌ์— ์ €์žฅ๋˜์ง€๋งŒ, ์ž๋™์œผ๋กœ ๋ณ‘ํ•ฉ(merge)๋˜์ง€๋Š” ์•Š์Œ
  • ๊ธฐ๋ณธ์ ์œผ๋กœ 'origin' ์›๊ฒฉ ์ €์žฅ์†Œ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ด

๋ฆฌ๋ชจํŠธ ์ €์žฅ์†Œ์˜ ๋ธŒ๋žœ์น˜๋ฅผ ๋กœ์ปฌ์—์„œ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜์—ฌ, ํ•„์š”ํ•œ ์‹œ์ ์— ์–ธ์ œ๋“ ์ง€ merge๋ฅผ ํ•˜๊ฑฐ๋‚˜ ๋ฆฌ๋ชจํŠธ ์ €์žฅ์†Œ์˜ ๋‚ด์šฉ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

git pull

  • ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๊ฐ€์ ธ์™€์„œ merge๊นŒ์ง€ ํ•œ๋ฒˆ์— ์ˆ˜ํ–‰
  • ํ˜„์žฌ ์ž‘์—… ์ค‘์ธ ๋ธŒ๋žœ์น˜์— ์ฆ‰์‹œ merge๋จ

git pull์„ ํ†ตํ•ด ์•„๋ž˜ ๋‘ ๋ช…๋ น์–ด(git fetch,git merge origin/main)๋ฅผ ์—ฐ์†์œผ๋กœ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™์€ ํšจ๊ณผ๋ฅผ ์–ป์„ ์žˆ๋‹ค.

git fetch
git merge origin/main

 

 

 

์‚ฌ์šฉ์ด ์ ์ ˆํ•œ ์ƒํ™ฉ

fetch

- ์›๊ฒฉ์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๋จผ์ € ๊ฒ€ํ† ํ•˜๊ณ  ์‹ถ์„ ๋•Œ

- ํ˜„์žฌ ์ž‘์—… ์ค‘์ธ ๋‚ด์šฉ์ด ์žˆ์„ ๋•Œ

- ์ถฉ๋Œ ๊ฐ€๋Šฅ์„ฑ์„ ๋จผ์ € ํ™•์ธํ•˜๊ณ  ์‹ถ์„ ๋•Œ

pull

- ์›๊ฒฉ์˜ ์ตœ์‹  ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๋ฐ”๋กœ ์ ์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ

- ๋กœ์ปฌ ์ž‘์—…์ด ์—†๊ฑฐ๋‚˜ ์ถฉ๋Œ ๊ฐ€๋Šฅ์„ฑ์ด ๋‚ฎ์„ ๋•Œ

- ๋น ๋ฅด๊ฒŒ ๋™๊ธฐํ™”๊ฐ€ ํ•„์š”ํ•  ๋•Œ

 

 

 

 

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

https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes

 

Git - Working with Remotes

Remote repositories can be on your local machine. It is entirely possible that you can be working with a “remote” repository that is, in fact, on the same host you are. The word “remote” does not necessarily imply that the repository is somewhere e

git-scm.com

https://git-scm.com/docs/git-fetch

 

Git - git-fetch Documentation

The fetch and push protocols are not designed to prevent one side from stealing data from the other repository that was not intended to be shared. If you have private data that you need to protect from a malicious peer, your best option is to store it in a

git-scm.com

 

728x90