.gitignore 설정


1. .gitignore란?


2. 작성 위치


3. 패턴 작성법

3.1 기본 규칙

패턴

설명

*.log

.log 확장자 파일 전체 무시

build/

build 디렉토리 무시

/secret.txt

루트 경로의 secret.txt만 무시

*.pem

.pem 인증서 파일 전체 무시

!.gitignore

.gitignore 파일은 무시하지 않음


3.2 주석 사용

# 로그 파일 무시
*.log

3.3 제외 항목 설정

# 모든 .env 파일은 무시
*.env

# 단, .env.example은 추적
!.env.example

4. 자주 사용하는 .gitignore 예시

4.1 Node.js

node_modules/
npm-debug.log
.env
dist/

4.2 Python

__pycache__/
*.py[cod]
.env
*.sqlite3

4.3 Java (IntelliJ 포함)

*.class
*.jar
*.war
*.log
target/
.idea/
*.iml

5. 이미 추적 중인 파일 무시하기

.gitignore에 추가했지만 이미 추적 중인 파일은 무시되지 않는다.

5.1 캐시 삭제 후 반영

git rm --cached 파일명

또는 전체 캐시 삭제:

git rm -r --cached .
git add .
git commit -m "Update .gitignore rules"

6. .gitignore 생성 도구 추천


✅ 참고 팁




Revision #2
Created 20 May 2025 23:54:10 by Dain
Updated 5 June 2025 02:49:21 by Dain