Git. 2장 git 저장 제외처리

2023. 2. 7. 00:25Git

Git의 관리에서 특정 파일/폴더를 배제해야 할 경우

a. 포함할 필요가 없을 

  • 자동으로 생성 또는 다운로드되는 파일들 (빌드 결과물, 라이브러리)

b. 포함하지 말아야 할 

  • 보안상 민감한 정보를 담은 파일(로그인 정보, 서버정보 등등)

.gitignore 파일을 사용해서 배제할 요소들을 지정할 수 있습니다.

secrets.yaml

id: admin
pw: 1234abcd
 
$ git status
---------------------------------------------------------------------------------------------------------
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        lions.yaml
        secrets.yaml
        tigers.yaml


nothing added to commit but untracked files present (use "git add" to track)
---------------------------------------------------------------------------------------------------------
 
.gitignore 생성
-gitignore에 
  secrets.yaml
 
추가
 
$ git status
---------------------------------------------------------------------------------------------------------
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore 
        lions.yaml 
        tigers.yaml

nothing added to commit but untracked files present (use "git add" to track)

 

.gitignore 형식

https://git-scm.com/docs/gitignore 참조

# 이렇게 #를 사용해서 주석
# 모든 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