Excluded files or folders from future commits (without deleting them locally)

DevNotes
By -
0

1️⃣ Clone the repository

git clone https://github.com/USERNAME/REPO.git

cd REPO

This pulls everything that already exists in the repo.

2️⃣ Create or edit .gitignore

Create a .gitignore file (or open it if it already exists):

nano .gitignore

# or

code .gitignore

Example .gitignore
# Python
__pycache__/
*.pyc
.venv/

# Logs
*.log

# Env
.env

# Build
dist/
build/

# OS
.DS_Store
Thumbs.db
➡️ Important: .gitignore only affects future tracking, not files already tracked.

3️⃣ Stop tracking files that are already in Git (KEEP them locally)

If files already exist in Git history, you must untrack them.

Untrack a file

git rm --cached path/to/file
Untrack a folder
git rm --cached -r path/to/folder
ex:
git rm --cached -r .venv
git rm --cached .env

✔ File stays on your machine
✔ Git stops tracking it


4️⃣ Commit the .gitignore and untracking changes

git status
git add .
git commit -m "Add .gitignore and stop tracking ignored files"
git push origin main

5️⃣ Verify ignored files

git status --ignored

Tags:
Git

Post a Comment

0 Comments

Post a Comment (0)
3/related/default