
Git RoadMap
Essential Git Cheatsheet!
🔧 Basic Commands
git init – Initialize a new Git repository.
git clone <repo_url> – Clone a remote repository.
git status – Check the status of your working directory.
git add <file> – Stage changes for commit.
git commit -m "message" – Commit staged changes with a message.
git push – Push your local commits to the remote repository.
git pull – Fetch and merge changes from the remote repo.
git diff – Show changes in the working directory (uncommitted changes).
git diff --staged – Show changes between the staging area and last commit.
🛠️ Branching & Merging
git branch – List branches.
git branch <branch_name> – Create a new branch.
git checkout <branch_name> – Switch to another branch.
git checkout -b <branch_name> – Create and switch to a new branch.
git merge <branch_name> – Merge a branch into the current one.
git branch -d <branch_name> – Delete a branch after merging.
git branch -D <branch_name> – Forcefully delete a branch, even if it hasn’t merged.
🔄 Synchronization
git fetch – Download changes from remote without merging.
git rebase <branch> – Reapply commits on top of another branch to maintain linear history.
git pull --rebase – Fetch and reapply your changes on top of the latest remote changes.
git remote add <name> <url> – Add a new remote repository.
🎯 Advanced Git
git stash – Temporarily save changes without committing.
git stash pop – Reapply stashed changes.
git cherry-pick <commit> – Apply a specific commit to your current branch.
git log --oneline – View simplified commit history.
git reflog – Show the history of your reference changes (e.g., checkout, resets).
git log --graph --decorate --all – Show a visual commit history.
🚨 Undoing Changes
git reset <file> – Unstage a file.
git reset --soft <commit> – Reset to a commit but keep changes in the working directory.
git reset --hard <commit> – Completely reset to a previous commit, discarding changes.
git revert <commit> – Create a new commit that undoes a specific commit.
⚙️ Collaborating with Others
git fork – Fork a repository on GitHub (via UI) to start contributing.
git pull origin <branch> – Pull changes from the original remote branch.
git push origin <branch> – Push your branch to the original repository for collaboration.
Bảng tiếng việt
🔧 Các lệnh cơ bản
-
git init
👉 Khởi tạo một repository Git mới trong thư mục hiện tại. Thư mục đó sẽ có thư mục .git để Git theo dõi thay đổi. -
git clone <repo_url>
👉 Tải về (sao chép) toàn bộ repository từ xa (thường trên GitHub, GitLab...) về máy tính của bạn. -
git status
👉 Xem trạng thái hiện tại: file nào đã thay đổi, đã stage chưa, có gì mới chưa commit... -
git add <file>
👉 Đưa file vào khu vực chuẩn bị commit (staging area). Có thể dùng . để add toàn bộ. -
git commit -m "message"
👉 Tạo một bản ghi (commit) với nội dung thay đổi kèm tin nhắn mô tả. -
git push
👉 Đẩy các commit từ máy local lên repository từ xa (như GitHub). -
git pull
👉 Lấy và hợp nhất thay đổi từ repository từ xa về local. -
git diff
👉 Hiển thị sự khác biệt giữa các file đã sửa và phiên bản đã commit trước đó. -
git diff --staged
👉 Hiển thị sự khác biệt giữa các file đã stage và commit cuối cùng.
🛠️ Làm việc với nhánh (Branching & Merging)
-
git branch
👉 Liệt kê tất cả các nhánh hiện tại. -
git branch <branch_name>
👉 Tạo nhánh mới. -
git checkout <branch_name>
👉 Chuyển sang làm việc với nhánh khác. -
git checkout -b <branch_name>
👉 Tạo nhánh mới và chuyển luôn sang nhánh đó. -
git merge <branch_name>
👉 Hợp nhất (merge) nhánh <branch_name> vào nhánh hiện tại. -
git branch -d <branch_name>
👉 Xoá nhánh sau khi đã merge. -
git branch -D <branch_name>
👉 Xoá mạnh tay nhánh (dù chưa merge).
🔄 Đồng bộ hóa với repository từ xa
-
git fetch
👉 Lấy dữ liệu mới từ repository từ xa nhưng không merge. -
git rebase <branch>
👉 Áp dụng lại các commit theo kiểu tuyến tính, giúp lịch sử gọn gàng hơn. -
git pull --rebase
👉 Kết hợp việc pull và rebase — rất hữu ích khi làm việc nhóm. -
git remote add <name> <url>
👉 Thêm một repository từ xa mới (ví dụ origin, upstream...).
🎯 Lệnh Git nâng cao
-
git stash
👉 Lưu lại tạm thời các thay đổi chưa commit — rất tiện khi cần chuyển nhánh gấp. -
git stash pop
👉 Áp dụng lại các thay đổi đã stash. -
git cherry-pick <commit>
👉 Lấy một commit cụ thể từ nhánh khác và áp dụng vào nhánh hiện tại. -
git log --oneline
👉 Hiển thị lịch sử commit ngắn gọn (mỗi commit trên 1 dòng). -
git reflog
👉 Xem toàn bộ lịch sử hoạt động, kể cả các lần checkout hay reset. -
git log --graph --decorate --all
👉 Hiển thị lịch sử commit dạng cây rất trực quan.
🚨 Hoàn tác thay đổi
-
git reset <file>
👉 Bỏ staging cho file (chuyển file ra khỏi vùng chuẩn bị commit). -
git reset --soft <commit>
👉 Quay lại một commit trước đó, giữ lại thay đổi trong thư mục làm việc. -
git reset --hard <commit>
👉 Quay lại hoàn toàn, xoá toàn bộ thay đổi sau commit đó. -
git revert <commit>
👉 Tạo một commit mới để đảo ngược tác động của commit cụ thể.
⚙️ Hợp tác với người khác
-
git fork
👉 Thực hiện thao tác "Fork" trên GitHub để tạo bản sao của repo bạn muốn đóng góp. -
git pull origin <branch>
👉 Lấy code mới từ nhánh <branch> của remote tên origin. -
git push origin <branch>
👉 Đẩy nhánh hiện tại lên repository từ xa.
Câu hỏi "có bao nhiêu loại Git?" có thể hiểu theo nhiều cách khác nhau. Để trả lời đầy đủ, mình sẽ chia ra một vài hướng giải thích để bạn chọn đúng ý bạn cần:
✅ 1. Về loại Git theo hình thức cài đặt / sử dụng:
Loại | Mô tả |
---|---|
Git CLI (Command Line Interface) | Dạng truyền thống, dùng dòng lệnh (git init, git status,...) |
Git GUI (Graphical User Interface) | Có giao diện đồ hoạ, ví dụ như: – Sourcetree – GitHub Desktop – GitKraken – SmartGit |
Git tích hợp trong IDE | Các công cụ như VSCode, PhpStorm, Android Studio có sẵn chức năng Git |
Git trên Web | Ví dụ: GitHub, GitLab, Bitbucket — quản lý Git repo trực tuyến, có thể edit file, commit, pull request v.v |
✅ 2. Về loại repository Git:
Loại | Mô tả |
---|---|
Local repository | Repo trên máy bạn (.git), nơi bạn làm việc trực tiếp. |
Remote repository | Repo từ xa (GitHub, GitLab,...), dùng để đồng bộ và làm việc nhóm. |
Bare repository | Repo chỉ để lưu trữ, không chứa code, thường dùng làm server trung gian để push/pull (không có working directory). |
✅ 3. Về loại lệnh Git (chia theo mục đích):
Nhóm lệnh | Mục đích |
---|---|
Lệnh cơ bản | init, add, commit, status, log |
Lệnh đồng bộ | push, pull, fetch, rebase |
Lệnh nhánh | branch, checkout, merge, rebase |
Lệnh sửa lỗi/hoàn tác | reset, revert, stash |
Lệnh nâng cao | cherry-pick, reflog, bisect |
✅ 4. Các nền tảng Git phổ biến hiện nay:
Nền tảng | Ghi chú |
---|---|
GitHub | Nổi tiếng nhất, hỗ trợ open-source mạnh mẽ |
GitLab | Cho phép tự host, CI/CD mạnh |
Bitbucket | Tích hợp tốt với Jira, phù hợp team sử dụng Atlassian |
Azure Repos | Git trong hệ sinh thái Microsoft Azure |
SourceForge / Codeberg / Gitea / Gogs | Các giải pháp thay thế, open-source, có thể tự host |
👉 Tóm lại:
Git thì chỉ có một "loại" chính là hệ thống quản lý mã nguồn phân tán, nhưng cách sử dụng và ứng dụng của nó thì đa dạng, chia thành nhiều hình thức, nền tảng, lệnh, và mô hình repository.
05 Comments

Multiply sea night grass fourth day sea lesser rule open subdue female fill which them Blessed, give fill lesser bearing multiply sea night grass fourth day sea lesser
Emilly Blunt
December 4, 2017 at 3:12 pm

Multiply sea night grass fourth day sea lesser rule open subdue female fill which them Blessed, give fill lesser bearing multiply sea night grass fourth day sea lesser
Emilly Blunt
December 4, 2017 at 3:12 pm
Multiply sea night grass fourth day sea lesser rule open subdue female fill which them Blessed, give fill lesser bearing multiply sea night grass fourth day sea lesser
Emilly Blunt
December 4, 2017 at 3:12 pm