.gitignore 파일

2022. 7. 25. 10:00·Git

.gitignore 파일이란, 사용자가 원하지 않는 파일들 즉, Git 버전 관리에서 제외할 목록을 지정하는 파일이다.

Git을 이용하다 보면 git에서는 올려서는 안 되거나 올리고 싶지 않을 파일들이 존재한다.

물론, 원하지 않는 파일들은 커밋하지 않으면 되지만 일일이 커밋에서 제외하기에는 귀찮고 불필요한 행동이다.

따라서, .gitignore 파일에 그런 파일들을 모두 넣어 관리해 줄 수 있다..

 

 

1. gitignore 파일 생성

vi .gitignore

 

git bash 에서 위 명령어를 실행하면 .gitignore를 생성할 수 있다.

그럼 .gitignore 파일에는 어떤 내용을 넣어 주어야 할까?

정답은 git의 추적을 피하고 싶은 파일명들이다.

 

만약 dismiss.md 파일을 git에서 제외시키고 싶다면 .gitignore파일에 dissmiss.md 를 적어주면 되는 것이다.

 

 

2. gitignore 내용 작성

물론 파일을 일일이 작성해주어도 좋지만, 그게 어렵다면 사이트를 이용하는 방법도 있다.

 

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

 

gitignore.io

Create useful .gitignore files for your project

www.toptal.com

 

.gitignore 파일을 자동으로 생성해주는 사이트다. 원하는 운영체제, 개발 환경, 프로그래밍 언어를 입력하면 .gitignore파일을 자동으로 생성해준다.

예시로 Python과 VScode 를 넣어보았다.

 

 

 

 

env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
#  JetBrains specific template is maintained in a separate JetBrains.gitignore that can
#  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
#  and can be added to the global gitignore or merged into this file.  For a more nuclear
#  option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# Support for Project snippet scope
.vscode/*.code-snippets

# Ignore code-workspaces
*.code-workspace

# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode

 

결과로 이런 긴 파일 내역이 생성되는데 복사해서 .gitignore 파일에 붙여넣어 저장하면 간단하게 파일 생성이 가능하다.

그러나 이미 git 버전 관리에 들어가 있는 파일들은 .gitignore 파일에 적용한다고 해도, 이미 관리가 되고 있는 파일이기 때문에 추적을 피할 수 없다. 

만약, 자신의 원격 저장소에 있는 파일을 삭제하고 더이상 추적을 받고 싶지않다면, 원격 저장소의 캐시를 모두 삭제하여 추적을 피할 수 있다.

 

$ git rm -r --cached .

 

다시 git add 를 이용해 파일을 추가하면 .gitignore 에 있는 파일들을 제외하고 다시  추적을 시작한다.

 

 

저작자표시 비영리 동일조건 (새창열림)

'Git' 카테고리의 다른 글

[Windows] Git 자동 완성 만들기  (0) 2022.07.22
'Git' 카테고리의 다른 글
  • [Windows] Git 자동 완성 만들기
수웅
수웅
  • 수웅
    야금야금 공부
    수웅
  • 전체
    오늘
    어제
    • 분류 전체보기 (65)
      • 알고리즘 (37)
      • CS (8)
      • 취준 (0)
      • 안드로이드 (15)
        • 코틀린 (6)
        • 정리 (9)
        • 프로젝트 (0)
      • Error (1)
      • Git (2)
      • 기타 (2)
  • 블로그 메뉴

    • 홈
    • 글쓰기
  • 링크

  • 공지사항

  • 인기 글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.4
수웅
.gitignore 파일
상단으로

티스토리툴바