.gitignore 파일 만들기
.gitignore 파일은 로컬 환경에서 민감한 파일 및 폴더에 대하여 git에 올라가지 않도록 관리하는 파일이다.
따라서 git clone을 통해 git repository를 로컬에 저장한 폴더에서 다음과 같은 명령어를 통해 .gitignore 파일을 만든다.
nano .gitignore
그리고 git에 올리지 않길 원하는 폴더 및 파일을 다음과 같이 정의해주면 된다.
# dataset 폴더를 제외하고 싶을 때
dataset/
# .txt 파일을 제외하고 싶을 때
*.txt
상당히 간단한다. 하지만 이 또한 귀찮으므로 아래의 사이트에서 자신의 개발 환경을 입력하면 알아서 .gitignore 파일을 기본적으로 작성해준다.
gitignore.io - 자신의 프로젝트에 꼭 맞는 .gitignore 파일을 만드세요

나의 경우 python, venv 를 추가하여 다음과 같은 .gitignore 파일을 얻었다.
# Created by https://www.toptal.com/developers/gitignore/api/python,venv
# Edit at https://www.toptal.com/developers/gitignore?templates=python,venv
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
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/
### venv ###
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json
# End of https://www.toptal.com/developers/gitignore/api/python,venv
git에 이미 올라가 있는 파일 및 폴더 삭제
만약 이미 원하지 않은 파일 및 폴더를 git에 push한 경우 다음과 같은 명령어를 통해 파일 및 폴더를 별도로 삭제해주어야 한다. (.gitignore 파일을 push한 이후에 추가한 파일 및 폴더는 알아서 제외되고 push된다.)
# dataset/ 폴더 삭제할 경우
git -- rm --cached dataset/ -r
# data.txt 파일 삭제할 경우
git -- rm --cached data.txt -r
References
🏋🏻 개인적으로 공부한 내용을 기록하고 있습니다.
잘못된 부분이 있다면 과감하게 지적해주세요!! 🏋
'etc' 카테고리의 다른 글
Mac(맥) M1에 Miniforge로 Python(파이썬), Tensorflow 설치하고 GPU 사용하기 (0) | 2021.11.22 |
---|---|
Mac(맥) capslock(캡스락) 길게 누르기(대문자) 기능 끄기 (0) | 2021.11.22 |
ssh에서 scp 명령어로 데이터(파일) 전송하기 (0) | 2021.11.22 |
댓글