출입금지!! 개인공부방/Git
.gitignore 사용 방법
해달e
2023. 8. 1. 17:37
Git에서 자동으로 생성, 다운로드 되는 파일들은 포함할 필요가 없고, 보안상 민감한 정보를 담은 파일은 포함하지 말아야한다. 따라서 .gitignore파일을 사용해서 포함되지 않도록 해줄 수 있다.
아래와 같이 secrets.yaml 파일을 생성한다.
그리고 .git ignore을 사용해서 아래와 같이 입력한다.
이후 git status를 통해서 확인하면 아래와 같다.
.git ignore 파일을 통해서 더이상 git이 secret.yaml을 관리하지 않는다.
요즘 프레임워크를 다운받아서 사용하면, .gitignore 파일들이 있고 자동으로 걸러야할 파일들을 입력해놓았다. 만약 직접 입력하고자하면, https://www.toptal.com/developers/gitignore 사이트의 도움을 받으면 된다.
https://git-scm.com/docs/gitignore
Git - gitignore Documentation
The optional configuration variable core.excludesFile indicates a path to a file containing patterns of file names to exclude, similar to $GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to those in $GIT_DIR/info/exclude.
git-scm.com
# 이렇게 #를 사용해서 주석
# 모든 file.c
file.c
# 최상위 폴더의 file.c
/file.c
# 모든 .c 확장자 파일
*.c
# .c 확장자지만 무시하지 않을 파일
!not_ignore_this.c
# logs란 이름의 파일 또는 폴더와 그 내용들
logs
# logs란 이름의 폴더와 그 내용들
logs/
# logs 폴더 바로 안의 debug.log와 .c 파일들
logs/debug.log
logs/*.c
# logs 폴더 바로 안, 또는 그 안의 다른 폴더(들) 안의 debug.log
logs/**/debug.log
출처: 얄코 깃허브