정리/Git

[Git] gitignore 작성하기

민발자 2024. 1. 8. 20:45
728x90

 

📌 .gitignore

프로젝트에서 백업하고 싶지 않는 파일이나 빌드 결과물 등 배제 요소들을 직접 지정해 git에서 제외할 수 있는 설정파일

  • 보안상 위험성이 있는 파일
  • 프로젝트와 관계 없는 파일
  • 용량이 너무 커서 제외해야하는 파일
  • IDE 관련 파일
  • 사용자가 제외하길 원하는 파일 등

 

 

📌 작성 규칙

표현 의미
# 주석의미
*.a 확장자가 a인 모든 파일 무시
폴더명/ 해당 폴더의 모든 파일 무시
폴더명/*.a 해당 폴더의 확장가가 a인 모든 파일 무시
폴더명/*/.a 해당 폴더 포함 하위 폴더에서 확장자가 .a인 모든 파일 무시
/*.a 현재 폴더의 확장자가 .a인 모든 파일 무시

 

사용자가 제외하기 원하는 파일을 작성할 수 있지만.. 모든 파일을 작성하기엔 어려움이 있다.

조금 더 찾아본 결과! 쉽게 작성하는 방법이 있었다.

검색을 통해 자동 생성해주는 사이트와 깃허브에서 제공하는 gitignore 파일을 참고하면 된다.

 

 

🗂️ gitignore 자동 생성

https://www.toptal.com/developers/gitignore

 

gitignore.io

Create useful .gitignore files for your project

www.toptal.com

사용중인 운영체제, IDE, 프로그래밍 언어 등을 검색하면 자동으로 생성해준다.

 

생성된 gitignore

 

 

🗂️ github 제공

https://github.com/github/gitignore

 

GitHub - github/gitignore: A collection of useful .gitignore templates

A collection of useful .gitignore templates. Contribute to github/gitignore development by creating an account on GitHub.

github.com

깃허브에서 각 프로젝트 환경에 맞게 샘플을 제공

 

 

📌 application.propertise

🗂️ application.properties 작성

application.propertise에서 올리고 싶지 않은 민감정보를 따로 관리하기 위해 작성해준다.

나는 DB관련된 것을 따로 작성해 주었다.

 

 

🗂️ application.properties include하기

spring.profiles.include=파일명

 

application.properties에 민감 정보를 작성한 파일을 include 해준다

 

 

🗂️ gitignore 적용

.gitignore 파일에 해당 properties를 추가해주면 민감정보는 github에 올라가지 않는다

application-secret.properties

 

 

 

 

 

728x90