Tạo file .gitignore cho dự án của bạn
Custom patterns (mỗi dòng 1 pattern):
# Generated by Tấn Phát Digital .gitignore Generator # Node.js node_modules/ npm-debug.log* yarn-debug.log* yarn-error.log* .npm .yarn-integrity # IDE .idea/ .vscode/ *.swp *.swo *~ .project .classpath .settings/ # OS .DS_Store Thumbs.db ehthumbs.db Desktop.ini *.lnk # Environment .env .env.local .env.*.local *.pem *.key
Công cụ tạo file .gitignore online miễn phí của Tấn Phát Digital là giải pháp không thể thiếu cho developers khi khởi tạo dự án mới. File .gitignore cho Git biết những files và folders nào không cần track trong version control - giúp repo sạch sẽ, không commit nhầm node_modules (hàng trăm MB), .env (chứa secrets), build outputs, IDE configs, hay OS files. Công cụ cung cấp templates có sẵn cho các ngôn ngữ và frameworks phổ biến: Node.js, Next.js, React, Vue, Python, Java, Go, Rust, và nhiều hơn nữa. Bao gồm patterns cho IDEs (VS Code, IntelliJ, Vim), Operating Systems (macOS .DS_Store, Windows Thumbs.db), logs, test coverage, và build artifacts. Bạn có thể combine nhiều templates, thêm custom patterns, preview kết quả, và download file .gitignore sẵn sàng sử dụng. Không cần nhớ patterns phức tạp, không cần search Stack Overflow.
File .gitignore là một trong những files quan trọng nhất trong mọi Git repository. Không có .gitignore đúng, bạn có thể: Commit nhầm node_modules (hàng trăm MB, hàng nghìn files) làm repo bloated. Leak secrets trong .env files (API keys, database passwords) - security risk nghiêm trọng. Commit build outputs (dist/, build/) không cần thiết. Commit IDE configs (.idea/, .vscode/) gây conflicts giữa team members dùng IDEs khác nhau. Commit OS files (.DS_Store, Thumbs.db) vô nghĩa. Những gì nên ignore: Dependencies (node_modules, vendor, venv). Environment files (.env, .env.local). Build outputs (dist, build, out, .next). IDE/Editor configs (.idea, .vscode, *.swp). OS files (.DS_Store, Thumbs.db). Logs (*.log, npm-debug.log). Test coverage (coverage/, .nyc_output).
Blank lines và lines bắt đầu bằng # là comments. Pattern không có / match ở bất kỳ đâu trong repo. Pattern có / ở cuối chỉ match directories. Pattern có / ở đầu match từ root của repo. * match mọi thứ trừ /. ** match mọi thứ kể cả /. ? match một ký tự bất kỳ. [abc] match a, b, hoặc c. ! ở đầu negates pattern (unignore). Ví dụ: *.log (ignore tất cả .log files), /build (ignore build/ ở root), doc/**/*.pdf (ignore PDFs trong doc/ và subdirectories), !important.log (không ignore important.log dù có *.log).
.gitignore chỉ ảnh hưởng đến untracked files. Files đã được commit trước đó vẫn được track dù có trong .gitignore. Để untrack: git rm --cached <file> (giữ file trên disk, xóa khỏi Git). git rm --cached -r <folder> (cho folders). Sau đó commit: git commit -m 'Remove tracked files that should be ignored'. Lưu ý: Điều này sẽ xóa files khỏi repo cho tất cả team members khi họ pull. Nếu files chứa secrets đã bị commit, cần rotate secrets vì chúng đã trong Git history.
Ngoài project .gitignore, bạn có thể có global .gitignore cho files cá nhân không nên commit vào bất kỳ repo nào. Tạo file: ~/.gitignore_global. Cấu hình Git: git config --global core.excludesfile ~/.gitignore_global. Nội dung phổ biến: .DS_Store (macOS), Thumbs.db (Windows), *.swp (Vim), .idea/ (IntelliJ), .vscode/ (VS Code). Điều này giúp không cần thêm IDE/OS patterns vào mỗi project .gitignore, giữ project .gitignore clean và focused vào project-specific patterns.
Khi bạn chạy git status hoặc git add, Git đọc file .gitignore và bỏ qua các files/folders match với patterns trong đó. Những files này sẽ không xuất hiện trong 'Untracked files' và không thể add vào staging area (trừ khi dùng git add -f để force). .gitignore chỉ ảnh hưởng đến untracked files - files đã được commit trước đó vẫn được track.
Không. .gitignore chỉ ảnh hưởng đến untracked files. Để stop tracking file đã commit: (1) Thêm pattern vào .gitignore, (2) Chạy 'git rm --cached <file>' để untrack (giữ file trên disk), (3) Commit changes. Sau đó file sẽ bị ignore. Lưu ý: File vẫn còn trong Git history - nếu chứa secrets, cần rotate.
Đặt ở root của repository (cùng level với .git folder). Bạn cũng có thể có .gitignore trong subdirectories - patterns trong đó chỉ apply cho subdirectory đó. Ngoài ra, có thể có global .gitignore (~/.gitignore_global) cho patterns cá nhân apply cho tất cả repos.
node_modules có thể chứa hàng nghìn files và hàng trăm MB. Commit nó sẽ: Làm repo bloated, clone/pull chậm. Gây conflicts khi dependencies update. Không cần thiết vì có thể recreate từ package.json bằng npm install. Có thể chứa platform-specific binaries không work trên OS khác. Best practice: Commit package.json và package-lock.json, ignore node_modules.
Dùng negation pattern với !. Ví dụ: Ignore tất cả trong folder nhưng giữ một file: folder/* (ignore all), !folder/keep-this.txt (unignore specific file). Lưu ý: Không thể unignore file nếu parent directory đã bị ignore. Phải ignore contents (folder/*) thay vì folder (folder/).
Chúng tôi không chỉ thiết kế website, mà còn giúp doanh nghiệp xây dựng thương hiệu số mạnh mẽ. Cung cấp dịch vụ thiết kế website trọn gói từ thiết kế đến tối ưu SEO. Hãy liên hệ ngay với Tấn Phát Digital để cùng tạo nên những giải pháp công nghệ đột phá, hiệu quả và bền vững cho doanh nghiệp của bạn tại Hồ Chí Minh.