.gitignore 파일
.gitignore 파일은 Git 버전 관리 시스템에서 특정 파일 또는 디렉토리를 버전 관리에서 제외할 수 있도록 지정하는 설정 파일입니다. 주로 프로젝트에서 버전 관리할 필요가 없는 파일(예: 로그 파일, 빌드 아티팩트, IDE 설정 파일, 민감한 환경 설정 파일 등)을 Git 저장소에 추가되지 않도록 보호할 수 있습니다.
1. .gitignore 파일의 주요 목적
- 불필요한 파일 무시: 프로젝트에서 자동 생성되거나 개발 환경에서만 필요한 파일(로그 파일, 빌드 결과 파일 등)을 제외.
- 보안 유지: 민감한 정보(환경 설정 파일, 인증서, API 키 등)가 버전 관리에 포함되지 않도록 보호.
- 프로젝트의 깨끗한 관리: 코드베이스를 필요한 파일로만 구성하여 깔끔하고 관리하기 쉽게 유지.
2. .gitignore 파일의 기본 구조
.gitignore 파일은 다음 규칙을 기반으로 파일 및 디렉토리를 무시합니다:
- 일반적인 파일 무시
- 특정 파일: 파일명.txt
- 특정 확장자: *.log
- 디렉토리 무시
- 특정 디렉토리: logs/
- 모든 하위 디렉토리의 특정 디렉토리 무시: **/logs/
- 특정 파일 제외 (예외 설정)
- 예외 설정: !important-file.txt
- 예외로 지정된 파일은 무시 규칙을 무시하고 버전 관리에 포함됨.
3. .gitignore 파일의 작성 위치
- 프로젝트 루트: 가장 일반적으로 .gitignore 파일은 프로젝트의 최상위 디렉토리에 위치.
- 하위 디렉토리: 특정 디렉토리마다 별도로 .gitignore 파일을 설정할 수 있음.
- 전역 .gitignore: 사용자 시스템 전체에 적용되는 전역 .gitignore 파일을 설정할 수 있음.
bash
복사편집
git config --global core.excludesfile ~/.gitignore_global
4. .gitignore 파일의 동작
- .gitignore 파일에 정의된 패턴은 아직 버전 관리되지 않은 파일에만 적용됨.
- 이미 버전 관리 중인 파일은 .gitignore 파일에 추가해도 무시되지 않음.
- 이미 버전 관리된 파일을 무시하려면 캐시를 삭제해야 함.
bash
복사편집
git rm --cached 파일명.txt git commit -m "Remove file from version control"
5. .gitignore 파일 템플릿
- 템플릿을 git 저장소에 복사한 후 필요한 부분만 남겨놓으면 된다.
- 혹은 https://www.toptal.com/developers/gitignore 에서 키워드들을 추가하면서 새로운 템플릿을 만들 수도 있다.
gitignore.io
Create useful .gitignore files for your project
www.toptal.com
# Created by https://www.toptal.com/developers/gitignore/api/macos
# Edit at https://www.toptal.com/developers/gitignore?templates=macos
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### macOS Patch ###
# iCloud generated files
*.icloud
# End of https://www.toptal.com/developers/gitignore/api/macos
'Tech > [SCM] Git & Github' 카테고리의 다른 글
현대적인 Git Branch 전략 비교 (0) | 2025.03.09 |
---|---|
Git 핵심 요약 (0) | 2025.03.09 |
Github 모든 커밋 초기화 (0) | 2021.10.08 |
Github Branch 삭제하는 방법 (0) | 2021.10.08 |
Github Default Branch 변경하는 방법 (0) | 2021.10.08 |