서론
기존 프로젝트를 진행하면서, 작업 내용을 git에 commit 할 때 작업한 내용 외에 불필요한 .gradle, .idle 등의 파일들이 노출되는 것을 본 적이 있을 것이다. 이를 제어할 수 있는 gitignore에 관해 정리해보려 한다🤗
gitignore란?
내가 gitignore을 쓴 목적은 커밋할 때 수정한 내용 외에 다른 내용이 노출되는걸 원치 않아서였다.
원래 gitignore는 민감한 정보가 들어있는 파일이나 형상관리할 필요가 없는 파일들을 git에서 더 이상 추적하지 않도록 gitignore 파일에 정의하여 제외하는 용도로 쓰인다고 한다.
제외할 파일의 예시
- 보안적으로 위험성이 있는 파일을 제외 해야하는 경우 (키, 스토어 등)
- 프로젝트와 관계없는 파일을 제외해야하는 경우
- 용량이 큰 파일을 제외해야하는 경우
gitignore 사용법
형상관리가 필요없는 파일을 gitignore 파일에 추가한 뒤 프로젝트의 root 폴더에 위치시키면 된다.
아래는 프로젝트에 맞게 gitignore 파일을 생성해 주는 사이트이다. 참고하면 좋을 듯하다!
gitignore.io
Create useful .gitignore files for your project
www.toptal.com
위와 같이 현재 프로젝트에 필요한 내용들을 입력한 후 생성해 주었다.
# Created by https://www.toptal.com/developers/gitignore/api/android,java,kotlin,windows
# Edit at https://www.toptal.com/developers/gitignore?templates=android,java,kotlin,windows
### Android ###
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Log/OS Files
*.log
# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json
# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml
# Keystore files
*.jks
*.keystore
# Google Services (e.g. APIs or Firebase)
google-services.json
# Android Profiling
*.hprof
### Android Patch ###
gen-external-apklibs
# Replacement of .externalNativeBuild directories introduced
# with Android Studio 3.5.
### Java ###
# Compiled class file
*.class
# Log file
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
### Kotlin ###
# Compiled class file
# Log file
# BlueJ files
# Mobile Tools for Java (J2ME)
# Package Files #
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.toptal.com/developers/gitignore/api/android,java,kotlin,windows
이렇게 생성된 gitignore 파일을 프로젝트의 root 폴더에 위치시키면 셋팅 완료👍
Reference
[Git] gitignore을 이용한 프로젝트 파일 관리
Git을 이용하여 프로젝트를 관리하면서 불필요한 파일을 제외하려고 할 때나 , 스토어용 파일 같은 민감한 파일들을 Git에서 관리할 때 gitignore를 사용한다고 한다. gitignore에 대해서 알아보자.
velog.io