Git Handbook
04 · Remote & Collaboration
Remote, origin, fetch, pull, push, upstream tracking và cách suy nghĩ khi nhiều developer cùng làm việc.
1. Remote chỉ là tên + URL/path
git-remote
Quản lý remote repository definitions.
git remote -v
git remote add origin git@github.com:org/project.git
git remote set-url origin NEW_URL
git remote remove origin2. Fetch trước, integrate sau
git-fetch
Tải refs/objects mới từ remote mà không tự merge vào branch hiện tại.
git fetch origin
git fetch --prune origin
git log --oneline main..origin/main--prune dọn remote-tracking refs đã bị xóa trên remote.git-pull
Fetch rồi integrate vào branch hiện tại.
git pull origin main
git pull --rebase origin main3. Push
git-push
Cập nhật refs trên remote bằng commit local.
git push -u origin feature/login
git push
git push origin --delete feature/oldKhông dùng
git push --force như thói quen. Nếu thật sự rewrite feature branch, ưu tiên --force-with-lease.4. Upstream / tracking branch
Khi chạy:
git push -u origin feature/loginGit thiết lập upstream để lần sau có thể dùng ngắn:
git push
git pullKiểm tra:
git branch -vv
git status -sb5. Mô hình collaboration
Developer A local ---- central remote
/
Developer B local ----/
A: commit -> push
B: fetch -> inspect -> integrate -> pushBạn sẽ thực hành mô hình này hoàn toàn local trong Lab 5.