Repository
Repository là gì?
Repository (hay “repo”) là thư mục dự án được Git quản lý. Nó chứa:
- Toàn bộ source code
- Lịch sử thay đổi (commits)
- Các branch
- Cấu hình Git của dự án
Tạo Repository mới
Khởi tạo repo trong thư mục hiện có
# Di chuyển vào thư mục dự án
cd my-project
# Khởi tạo Git
git initKết quả:
Initialized empty Git repository in /path/to/my-project/.git/Tạo thư mục mới và khởi tạo
git init my-new-project
cd my-new-projectCấu trúc thư mục .git
Sau khi git init, Git tạo thư mục ẩn .git/:
.git/
├── HEAD # Con trỏ đến branch hiện tại
├── config # Cấu hình local của repo
├── description # Mô tả (cho GitWeb)
├── hooks/ # Scripts tự động
├── info/ # Thông tin bổ sung
├── objects/ # Dữ liệu Git (commits, files...)
└── refs/ # Con trỏ đến commits (branches, tags)⚠️ Cảnh báo: Không chỉnh sửa trực tiếp thư mục
.git/trừ khi bạn biết mình đang làm gì!
Clone Repository
Tải một repo có sẵn từ remote (GitHub, GitLab…):
git clone https://github.com/user/repo.gitClone vào thư mục với tên khác:
git clone https://github.com/user/repo.git my-folderKiểm tra trạng thái
git statusKết quả:
On branch main
nothing to commit, working tree cleanFile .gitignore
Tạo file .gitignore để Git bỏ qua các file không cần track:
# Dependencies
node_modules/
venv/
__pycache__/
# Build output
dist/
build/
*.pyc
# IDE
.vscode/
.idea/
# Environment
.env
.env.local
# OS files
.DS_Store
Thumbs.db💡 Tip: Tạo
.gitignorengay khi bắt đầu dự án để tránh commit nhầm file.
Xóa Repository
Xóa Git khỏi dự án (giữ lại code)
rm -rf .gitXóa toàn bộ thư mục
rm -rf my-projectTiếp theo
Học cách tạo Commit để lưu lại các thay đổi của bạn.
Last updated on