[Git] gitignore 설정하기, gitignore 자동으로 설정해주는 사이트



.gitignore를 어떻게 설정해야 하나?

개요

안드로이드 개인 프로젝트를 처음 하게 되면서, git에 프로젝트 파일들을 올려주는 과정에서 gitignore 파일을 제대로 설정해주지 않았더니 다른 노트북에서 프로젝트를 실행할 때 프로젝트가 빌드가 되지 않는 문제가 발생하였다.

gitignore 파일의 위치도 이상했을 뿐더러, gitignore에 어떤 것들을 추가해야하는지 모르는 상태에서 프로젝트 빌드에 필요한 Gradle 스크립트까지 모두 gitignore에 추가해버리니 오류가 나는 건 당연한 수순이었다. 나같은 초보자의 입장에선 매우 당황스러울 수 있으므로 내가 도움을 받았던, gitignore를 간단하게 설정할 수 있는 사이트를 소개하려고 한다.

1. .gitignore 파일의 위치

git을 공부한 사람에게는 당연한 얘기겠지만, .gitignore 파일은 프로젝트가 존재하는 최고 상위폴더에 위치시켜야 한다!

:bulb: [예시 : 안드로이드 프로젝트의 경우]

MyAndroidApp/   
  ├──app/   
    ├──src/
    ├──build/
    ├──libs/
  ├──gradle/   
  ├── settings.gradle   
  ├── build.gradle   
  ├── .gitignore   

2. .gitignore를 자동으로 구성해주는 사이트

www.gitignore.io

image1

위 사이트가 .gitignore에 들어갈 코드들을 자동으로 생성해주는 사이트이다. 검색창에 운영체제, IDE, 프로그래밍 언어, 플랫폼 등을 입력하고 ‘생성’ 버튼을 클릭하면 해당 키워드에 맞는 gitignore 파일을 자동으로 구성해준다.

image2

안드로이드 프로젝트를 진행할 경우 위와 비슷하게 키워드를 작성할 수 있다.
아래는 이렇게 검색하였을 때 나오는 gitignore 코드이다.

# Created by https://www.toptal.com/developers/gitignore/api/android,androidstudio,java,windows
# Edit at https://www.toptal.com/developers/gitignore?templates=android,androidstudio,java,windows

### Android ###
# Built application files
*.apk
*.aar
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
#  Uncomment the following line in case you need and you don't have the release build type files in your app
# release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/

### Android Patch ###
gen-external-apklibs
output.json

# Replacement of .externalNativeBuild directories introduced
# with Android Studio 3.5.

### Java ###
# Compiled class file

# 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*

### 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

### AndroidStudio ###
# Covers files to be ignored for android development using Android Studio.

# Built application files

# Files for the ART/Dalvik VM

# Java class files

# Generated files

# Gradle files
.gradle

# Signing files
.signing/

# Local configuration file (sdk path, etc)

# Proguard folder generated by Eclipse

# Log Files

# Android Studio
/*/build/
/*/local.properties
/*/out
/*/*/build
/*/*/production
*.ipr
*~
*.swp

# Android Patch

# External native build folder generated in Android Studio 2.2 and later

# NDK
obj/

# IntelliJ IDEA
*.iws
/out/

# User-specific configurations
.idea/caches/
.idea/libraries/
.idea/shelf/
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/encodings.xml
.idea/misc.xml
.idea/scopes/scope_settings.xml
.idea/vcs.xml
.idea/jsLibraryMappings.xml
.idea/datasources.xml
.idea/dataSources.ids
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml

# OS-specific files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes

# Legacy Eclipse project files
.classpath
.project
.cproject
.settings/

# Mobile Tools for Java (J2ME)

# Package Files #

# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)

## Plugin-specific files:

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Mongo Explorer plugin
.idea/mongoSettings.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### AndroidStudio Patch ###

!/gradle/wrapper/gradle-wrapper.jar

# End of https://www.toptal.com/developers/gitignore/api/android,androidstudio,java,windows



:bookmark: REFERENCE
Android 개발자>Android 스튜디오>사용자 가이드>빌드 구성
gitignore 적용하기
www.gitignore.io