{"id":50549935,"url":"https://github.com/thongnguyens/git-github-handbook","last_synced_at":"2026-06-04T02:30:37.494Z","repository":{"id":309852772,"uuid":"1037761175","full_name":"thongnguyens/git-github-handbook","owner":"thongnguyens","description":"Hướng dẫn Git \u0026 GitHub toàn diện: cài đặt cơ bản, SSH/GPG ký commit, GitHub Flow, GitHub CLI, Actions, Git LFS, bảo mật nhánh, và xử lý lỗi thường gặp.","archived":false,"fork":false,"pushed_at":"2025-08-14T05:11:33.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-14T07:05:22.325Z","etag":null,"topics":["branch-protection","codeowners","conventional-commits","documentation","git","git-cli","git-lfs","git-workflow","github","github-actions"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thongnguyens.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-14T04:48:17.000Z","updated_at":"2025-08-14T05:11:36.000Z","dependencies_parsed_at":"2025-08-14T07:05:24.110Z","dependency_job_id":"860b62d4-2aa5-4eb8-b00b-28b28976f43e","html_url":"https://github.com/thongnguyens/git-github-handbook","commit_stats":null,"previous_names":["thongnguyens/git-github-handbook"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/thongnguyens/git-github-handbook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thongnguyens%2Fgit-github-handbook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thongnguyens%2Fgit-github-handbook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thongnguyens%2Fgit-github-handbook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thongnguyens%2Fgit-github-handbook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thongnguyens","download_url":"https://codeload.github.com/thongnguyens/git-github-handbook/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thongnguyens%2Fgit-github-handbook/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33887124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-04T02:00:06.755Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["branch-protection","codeowners","conventional-commits","documentation","git","git-cli","git-lfs","git-workflow","github","github-actions"],"created_at":"2026-06-04T02:30:37.424Z","updated_at":"2026-06-04T02:30:37.489Z","avatar_url":"https://github.com/thongnguyens.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git \u0026 GitHub — Hướng Dẫn Sử Dụng Chi Tiết\n\n\u003e Cẩm nang thực chiến cho cá nhân \u0026 nhóm: cài đặt và cấu hình Git, SSH/GPG/SSH-signing, GitHub Flow (branch/PR), GitHub CLI, Branch protection \u0026 CODEOWNERS, Git LFS, rebase/cherry-pick/stash/revert/bisect, Actions \u0026 Secrets, `.gitignore`/`.gitattributes`, cùng xử lý lỗi phổ biến.\n\n---\n\n## Mục lục\n- [1) Chuẩn bị nhanh](#1-chuẩn-bị-nhanh)\n- [2) Cài đặt \u0026 cấu hình Git](#2-cài-đặt--cấu-hình-git)\n- [3) Kết nối GitHub (SSH \u0026 ký commit)](#3-kết-nối-github-ssh--ký-commit)\n- [4) Tạo repo \u0026 đồng bộ với GitHub](#4-tạo-repo--đồng-bộ-với-github)\n- [5) Quy trình làm việc nhóm (GitHub Flow)](#5-quy-trình-làm-việc-nhóm-github-flow)\n- [6) Bảng lệnh thường dùng](#6-bảng-lệnh-thường-dùng)\n- [7) Nâng cao: rebase/cherry-pick/stash/revert/bisect](#7-nâng-cao-rebasecherry-pickstashirevertbisect)\n- [8) .gitignore \u0026 .gitattributes (EOL/CRLF)](#8-gitignore--gitattributes-eolcrlf)\n- [9) Git LFS (file lớn) \u0026 Submodule](#9-git-lfs-file-lớn--submodule)\n- [10) GitHub CLI (gh)](#10-github-cli-gh)\n- [11) GitHub Actions \u0026 Secrets](#11-github-actions--secrets)\n- [12) Branch protection \u0026 CODEOWNERS](#12-branch-protection--codeowners)\n- [13) Xử lý lỗi hay gặp](#13-xử-lý-lỗi-hay-gặp)\n- [14) Alias \u0026 mẹo](#14-alias--mẹo)\n- [Tài liệu](#tài-liệu)\n- [Giấy phép](#giấy-phép)\n\n---\n\n## 1) Chuẩn bị nhanh\n```bash\n# Đặt nhánh mặc định là main (Git \u003e= 2.28)\ngit config --global init.defaultBranch main\n\n# Danh tính\ngit config --global user.name  \"Your Name\"\ngit config --global user.email \"you@example.com\"\n\n# SSH cho GitHub (khuyên dùng)\nssh-keygen -t ed25519 -C \"you@example.com\"\neval \"$(ssh-agent -s)\" \u0026\u0026 ssh-add ~/.ssh/id_ed25519\ncat ~/.ssh/id_ed25519.pub  # dán lên GitHub → Settings → SSH and GPG keys\n\n# Khởi tạo \u0026 đẩy lên GitHub\ngit init -b main\necho \"# My Project\" \u003e README.md\ngit add . \u0026\u0026 git commit -m \"chore: init\"\ngit remote add origin git@github.com:\u003cowner\u003e/\u003crepo\u003e.git\ngit push -u origin main\n```\n\n---\n\n## 2) Cài đặt \u0026 cấu hình Git\n```bash\ngit --version\n\ngit config --global user.name  \"Your Name\"\ngit config --global user.email \"you@example.com\"\ngit config --global init.defaultBranch main   # nhánh mặc định khi git init\ngit config --global log.date relative\ngit config --global color.ui auto\n```\n\u003e `init.defaultBranch` giúp `git init` tạo nhánh đầu tiên là **main** thay vì **master**.\n\n---\n\n## 3) Kết nối GitHub (SSH \u0026 ký commit)\n\n### SSH\n```bash\nssh-keygen -t ed25519 -C \"you@example.com\"\neval \"$(ssh-agent -s)\"\nssh-add ~/.ssh/id_ed25519\ncat ~/.ssh/id_ed25519.pub   # thêm vào GitHub\n```\n\n### Ký commit (Verified)\n- **GPG**: cài `gpg`, tạo key → `git config --global user.signingkey \u003cKEYID\u003e` → `git config --global commit.gpgsign true`.\n- **SSH signing** (Git ≥ 2.34): có thể dùng khóa SSH để ký commit/tag.\n- Có thể bật **Require signed commits** trong `Branch protection` để bắt buộc Verified.\n\n---\n\n## 4) Tạo repo \u0026 đồng bộ với GitHub\n\n### A) Tạo local rồi push\n```bash\nmkdir my-app \u0026\u0026 cd my-app\ngit init -b main\necho \"# My App\" \u003e README.md\ngit add . \u0026\u0026 git commit -m \"chore: initial commit\"\ngit remote add origin git@github.com:\u003cowner\u003e/\u003crepo\u003e.git\ngit push -u origin main\n```\n\n### B) Clone repo có sẵn\n```bash\ngit clone git@github.com:\u003cowner\u003e/\u003crepo\u003e.git\ncd \u003crepo\u003e\n```\n\n### C) Đồng bộ thường ngày\n```bash\ngit fetch --all --prune\ngit pull --rebase origin main\ngit push\n```\n\n---\n\n## 5) Quy trình làm việc nhóm (GitHub Flow)\n\n1. **Branch** từ `main`: `git switch -c feat/login`\n2. Commit nhỏ, rõ ràng (*Conventional Commits* khuyến nghị)\n3. Push \u0026 mở **Pull Request**\n4. Review + CI xanh, rồi merge (squash/rebase)\n5. Xoá nhánh tính năng sau khi merge\n\n**Conventional Commits ví dụ:**\n```\nfeat(auth): add OAuth login\nfix(api): handle 401 refresh\ndocs(readme): installation steps\nchore(ci): bump node to 20.x\n```\n\n---\n\n## 6) Bảng lệnh thường dùng\n```bash\n# Nhánh\ngit branch\ngit switch -c feat/x\ngit branch -M main\n\n# Trạng thái \u0026 lịch sử\ngit status\ngit diff\ngit diff --staged\ngit log --oneline --graph --decorate -n 20\n\n# Staging \u0026 commit\ngit add .              # hoặc: git add -p (chọn hunk)\ngit commit -m \"feat: ...\"\ngit commit --amend     # sửa commit gần nhất\n\n# Đồng bộ\ngit fetch --all --prune\ngit pull --rebase origin main\ngit push -u origin \u003cbranch\u003e\n\n# Tag\ngit tag v1.0.0\ngit push origin v1.0.0\n```\n\n---\n\n## 7) Nâng cao: rebase/cherry-pick/stash/revert/bisect\n\n**Rebase (sạch lịch sử)**\n```bash\ngit pull --rebase origin main\ngit rebase -i origin/main\n# sửa xung đột → git add \u003cfile\u003e → git rebase --continue\n# hủy rebase: git rebase --abort\n```\n\n**Cherry-pick (lấy commit lẻ)**\n```bash\ngit cherry-pick \u003ccommit\u003e [\u003ccommit2\u003e ...]\n```\n\n**Stash (cất tạm)**\n```bash\ngit stash push -u -m \"WIP\"\ngit stash list\ngit stash pop     # hoặc: git stash apply\n```\n\n**Revert (đảo commit bằng commit mới)**\n```bash\ngit revert \u003ccommit\u003e\n```\n\n**Bisect (tìm commit gây lỗi)**\n```bash\ngit bisect start\ngit bisect bad\ngit bisect good \u003cknown-good-commit\u003e\n# lặp lại test → good/bad\ngit bisect reset\n```\n\n---\n\n## 8) .gitignore \u0026 .gitattributes (EOL/CRLF)\n\n**`.gitignore` ví dụ:**\n```\n# deps/build\nnode_modules/\ndist/\n.build/\n\n# env \u0026 secrets\n.env\n.env.*\n\n# IDE\n.vscode/\n.idea/\n```\n\n**`.gitattributes` chuẩn hoá EOL:**\n```\n* text=auto\n```\n\n---\n\n## 9) Git LFS (file lớn) \u0026 Submodule\n\n**Git LFS**\n```bash\ngit lfs install\ngit lfs track \"*.psd\" \"*.mp4\" \"*.zip\"\ngit add .gitattributes\ngit add . \u0026\u0026 git commit -m \"chore(lfs): track large assets\"\ngit push\n```\n\n**Submodule**\n```bash\ngit submodule add https://github.com/org/lib lib/\ngit submodule update --init --recursive\n# sau này:\ngit submodule update --remote --merge\n```\n\n---\n\n## 10) GitHub CLI (gh)\n```bash\n# Đăng nhập (PAT classic: cần scopes tối thiểu repo, read:org, gist)\ngh auth login\ngh auth status\n\n# Tạo repo \u0026 đẩy source hiện tại\ngh repo create \u003cowner\u003e/\u003crepo\u003e --public --source=. --push\n\n# Pull Request\ngh pr create --fill --base main --head feat/login\ngh pr view --web\ngh pr merge --squash --delete-branch\n\n# Topics \u0026 mô tả\ngh repo edit \u003cowner\u003e/\u003crepo\u003e \\\n  --description \"My project\" \\\n  --add-topic git --add-topic github\n```\n\n---\n\n## 11) GitHub Actions \u0026 Secrets\n\n**Secrets:** Repo → Settings → *Secrets and variables* → *Actions*.  \n**Workflow Node.js tối giản:**\n```yaml\nname: CI\non: [push, pull_request]\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: actions/setup-node@v4\n        with: { node-version: 20 }\n      - run: npm ci\n      - run: npm test\n```\n\n---\n\n## 12) Branch protection \u0026 CODEOWNERS\n\n**Branch protection** (Settings → Branches → Add rule):\n- Require pull request reviews\n- Require status checks to pass\n- (Tuỳ chọn) Require signed commits\n- Restrict who can push\n\n**CODEOWNERS** (tự yêu cầu reviewer đúng người):\n```\n# .github/CODEOWNERS\n*           @team/core\ndocs/*      @team/docs\nsrc/api/*   @alice @bob\n```\n\n---\n\n## 13) Xử lý lỗi hay gặp\n\n**`error: src refspec main does not match any`**  \n→ Chưa có commit đầu tiên hoặc nhánh chưa là `main`  \n```\ngit add . \u0026\u0026 git commit -m \"init\"\ngit branch -M main\ngit push -u origin main\n```\n\n**`non-fast-forward` khi push**  \n→ Repo GitHub đã có lịch sử; pull trước:  \n```\ngit pull --rebase origin main\ngit push\n```\n\n**Thiếu scope khi dùng gh CLI**  \n```\ngh auth refresh -s repo -s read:org -s gist -s workflow\n```\n\n**File \u003e 100MB** → dùng Git LFS.\n\n**Lỗi CRLF/LF** → thêm `.gitattributes` với `* text=auto` rồi re-checkout nếu cần.\n\n---\n\n## 14) Alias \u0026 mẹo\n\n**Alias hữu ích:**\n```bash\ngit config --global alias.co \"checkout\"\ngit config --global alias.sw \"switch\"\ngit config --global alias.br \"branch\"\ngit config --global alias.cm \"commit -m\"\ngit config --global alias.st \"status -sb\"\ngit config --global alias.lg \"log --graph --oneline --decorate --all\"\ngit config --global alias.unstage \"reset HEAD --\"\ngit config --global alias.last \"log -1 HEAD\"\n```\n\n**Mẹo:**\n- `git add -p` để stage theo hunk → commit gọn và chuẩn.\n- Đặt `pull.rebase=true` để luôn rebase khi pull:\n  ```bash\n  git config --global pull.rebase true\n  ```\n\n---\n\n## Tài liệu\n- Pro Git (sách miễn phí): https://git-scm.com/book\n- Git docs: https://git-scm.com/docs\n- GitHub Docs: https://docs.github.com/\n- Git LFS: https://git-lfs.com/\n- GitHub CLI Manual: https://cli.github.com/manual/\n\n---\n\n## Giấy phép\nPhát hành theo **MIT License** — xem [LICENSE](./LICENSE).  \n\n\u003e Nội dung \u0026 tên thương hiệu của bên thứ ba giữ nguyên giấy phép và quyền sở hữu tương ứng.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthongnguyens%2Fgit-github-handbook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthongnguyens%2Fgit-github-handbook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthongnguyens%2Fgit-github-handbook/lists"}