Remote Repository
Remote là gì?
Remote là phiên bản repository được lưu trữ trên server (GitHub, GitLab, Bitbucket…). Cho phép:
- Backup code trên cloud
- Chia sẻ code với người khác
- Collaboration trong team
Xem danh sách Remote
git remote -vKết quả:
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)Thêm Remote
git remote add <name> <url>Ví dụ:
git remote add origin https://github.com/user/repo.git
git remote add upstream https://github.com/original/repo.gitĐổi URL Remote
git remote set-url origin https://github.com/user/new-repo.gitXóa Remote
git remote remove originPush - Đẩy code lên Remote
# Push lần đầu (thiết lập upstream)
git push -u origin main
# Các lần sau
git push
# Push branch cụ thể
git push origin feature-login
# Push tất cả branches
git push --all originPull - Kéo code về
# Pull từ remote mặc định
git pull
# Pull từ remote và branch cụ thể
git pull origin main💡
git pull=git fetch+git merge
Fetch - Lấy thông tin không merge
# Fetch từ tất cả remotes
git fetch --all
# Fetch từ remote cụ thể
git fetch origin
# Xem branches remote
git branch -rLàm việc với nhiều Remote
Ví dụ: Fork workflow
# origin = fork của bạn
git remote add origin https://github.com/you/repo.git
# upstream = repo gốc
git remote add upstream https://github.com/original/repo.git
# Sync với upstream
git fetch upstream
git checkout main
git merge upstream/mainXóa branch trên Remote
git push origin --delete feature-loginXem thông tin Remote
git remote show originTiếp theo
Học cách Hoàn tác thay đổi khi có lỗi xảy ra.
Last updated on