Git .gitignore File ์ ์šฉํ•˜๊ธฐ

.gitignore์ด๋ž€?

Project์— ์›ํ•˜์ง€ ์•Š๋Š” Backup File์ด๋‚˜ Log File , ํ˜น์€ ์ปดํŒŒ์ผ ๋œ ํŒŒ์ผ๋“ค์„ Git์—์„œ ์ œ์™ธ์‹œํ‚ฌ์ˆ˜ ์žˆ๋Š” ์„ค์ • File์ด๋‹ค.

1. .gitignore ํŒŒ์ผ ๋งŒ๋“ค๊ธฐ

  • ํ•ญ์ƒ ์ตœ์ƒ์œ„ Directory์— ์กด์žฌํ•ด์•ผํ•œ๋‹ค.

  • Ex) ์˜ˆ์‹œ

  • ๋ฌธ๋ฒ•
# : comments
 
# no .a files
*.a
 
# but do track lib.a, even though you're ignoring .a files above
!lib.a
 
# only ignore the TODO file in the current directory, not subdir/TODO
/TODO
 
# ignore all files in the build/ directory
build/
 
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
 
# ignore all .pdf files in the doc/ directory
doc/**/*.pdf

2. ์ ์šฉํ•˜๊ธฐ

  • ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์–ด๋ ต์ง€ ์•Š๋‹ค. .gitignore File์„ ๊ฐ™์ด Pushํ•˜๋ฉด ๋œ๋‹ค.
  • ๊ธฐ์กด์— ์žˆ๋˜ Project์— .gitignore File์ด ์ ์šฉ์ด ์•ˆ๋˜๋Š” ๊ฒฝ์šฐ์—๋Š” git Repository์—์„œ ์ ์šฉํ•ด๋ณด๊ณ  ๋‹ค์‹œ Pushํ•ด๋ณด๊ธฐ ๋ฐ”๋ž€๋‹ค.
git rm -r --cached .
git add .
git commit -m "Apply .gitignore"

3. ํ™•์ธํ•ด๋ณด๊ธฐ

  • Local์—์„œ๋Š” ignoreFile์ด ์‚ฌ๋ผ์ง€์ง€ ์•Š์•˜์ง€๋งŒ Remote์— Push๊ฐ€ ๋ ๋•Œ์—๋Š” ์ ์šฉ๋˜์–ด ์˜ฌ๋ผ๊ฐ„ ๋ชจ์Šต์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

Reference