Git Handbook
08 · Công cụ Git nâng cao
Stash, tags, worktree, sparse checkout, submodules, clean và archive cho các workflow phức tạp hơn.
1. Stash
git-stash
Tạm cất thay đổi working tree/index để quay lại sau.
git stash push -u -m "WIP payment"
git stash list
git stash show -p stash@{0}
git stash apply stash@{0}
git stash pop
git stash drop stash@{0}2. Tag & release
git-tag
Tạo/list/delete tag.
git tag -a v1.0.0 -m "Release v1.0.0"
git show v1.0.0
git push origin v1.0.0
git push origin --tags3. Worktree — nhiều branch cùng lúc
git-worktree
Quản lý nhiều working trees gắn với cùng repository.
git worktree add ../project-hotfix -b hotfix/payment main
git worktree add ../project-login feature/login
git worktree list
git worktree remove ../project-hotfixMỗi branch bình thường chỉ có thể checkout trong một worktree tại cùng thời điểm.
4. Repository lớn
git-sparse-checkout
Chỉ materialize một phần cây file trong working tree.
git sparse-checkout init --cone
git sparse-checkout set apps/web services/authgit-submodule
Quản lý repository được tham chiếu bên trong repository khác.
git submodule add https://github.com/org/shared.git libs/shared
git clone --recurse-submodules URL
git submodule update --init --recursive5. Clean & Archive
git-clean
Xóa untracked files/directories.
git clean -nd
git clean -fdĐây là lệnh phá hủy dữ liệu untracked.
git-archive
Xuất tree tại commit/tag thành archive không chứa metadata .git.
git archive --format=zip v1.0.0 > release-v1.0.0.zip