Khắc phục lỗi lệnh git modules cho .gitmodules không tải source code
Mình rất hay có thói quen sử dụng .gitmodules/ để nhúng theme và plugin đang trong quá trình phát triển hay bảo trì vào các dự án. Code Tốt hiện có base là ct-bones (theme cha) và ct-blocks (plugin) dùng cho khách hàng lập trình, và đôi khi cũng gặp tình huống không thể tải source về máy.
Ví dụ file `.gitmodules` có nội dung sau:
“`txt
[submodule “wp-content/plugins/ct-blocks”]
path = wp-content/plugins/ct-blocks
url = git@github.com:codetot-web/ct-blocks.git
[submodule “wp-content/themes/ct-bones”]
path = wp-content/themes/ct-bones
url = git@github.com:codetot-web/ct-bones.git
“`
Để sử dụng `git submodule`, ta cần chủ yếu hai câu lệnh sau:
– Sử dụng lần đầu khi lấy dự án, ta gõ `git submodule init`
– Để lấy source cập nhật của mỗi repository, ta chạy `git submodule update`
Nếu khi bạn chạy cả lệnh số 1 lẫn lệnh số 2 đều không có tác dụng, bạn sẽ phải chạy lại các source `git submodule add
Chẳng hạn, như với 2 repository ở trên, mình cần chạy lại:
“`
git submodule add git@github.com:codetot-web/ct-blocks.git wp-content/plugins/ct-blocks
git submodule add git@github.com:codetot-web/ct-bones.git wp-content/themes/ct-bones
“`
Kết quả là repository đã được kéo về từ GitHub và có thể sử dụng tiếp.