Rujukan di sini lebih teratur. Penerangan dibawah ialah berasaskan pengalaman sendiri tanpa struktur.
Repo baru
Bila buat repo baru dan ingin tetapkan submodule untuk tema harbor dan folder public ke yusbk.github.io. Submodule dipakai untuk memasukkan fungsi yang terdapat di repos lain ke dalam repos sendiri ie. subfolder di folder utama repos.
Contoh dibawah ialah untuk memasukkan folder harbor ke dalam folder themes di folder utama. Subfolder public pula ialah submodule dari repo blog di Github.
# themes
git submodule add https://github.com/matsuyoshi30/harbor.git themes/harbor
# yusbk.github.io master branch
git submodule add -b master git@personal:yusbk/yusbk.github.io.git public
# update
git submodule init
git submodule update --remote --merge
Untuk update submodule pakai komando di bawah. Penting commit submodule dahulu kemudian commit parent repo sebelum push dari parent repos. Caranya:
cd public
git add .
git commit -am 'Tambah pertukaran di public submodule'
cd ..
git push origin master --recurse-submodules=on-demand
Bila tambah fail baru, jangan lupa daftarkan fail tersebut dengan git add .
sebelum pakai git commit
. Sekiranya HEAD detaching dengan submodule boleh guna script ini untuk kembali ke MASTER.
Rujukan di StackOverflow.
#!/bin/bash
echo "Building all submodules while checking out from MASTER branch."
git submodule update
git submodule foreach git checkout master
git submodule foreach git pull origin master
Clone
Untuk clone repo termasuk semua submodules di repo boleh guna --recursive
:
git clone --recursive [URL to repo]
Bila selesai compile dengan hugo -D
, ikut cara ini untuk push pertama kali:
cd public
git add .
git commit -am "you commit message"
git push origin HEAD:master
cd ..
git submodule update --remote
git add .
git commit -am "your commit message"
git push --recurse-submodules=on-demand
Bila clone repos tanpa --recursive
yang mempunyai submodules, folder-folder submodule akan hanya
kosong. Untuk dapatkan isi kandungan submodels tersebut harus larikan komando:
git submodule update --init
## sekiranya ada nested submodules
git submodule update --init --recursive
git submodule update --rebase --merge
Sekiranya masih kosong, boleh letak --recursive
disebabkan nested submodules ../themes/harbor
. Bila
sudah selesai pasang aturcara, bolehlah kemaskini submodule dengan fetch/pull
.
# pull all changes in the repo including changes in the submodules
git pull --recurse-submodules
# pull all changes for the submodules
git submodule update --remote
Sekiranya masih tidak berhasil, padamkan folder submodule harbor
dan larikan semua komando:
git submodule set-url themes/harbor https://github.com/matsuyoshi30/harbor.git
git submodule sync
git submodule update --rebase --remote --merge --recursive
Sekiranya HEAD detached
, boleh coba checkout master
dan pull
semula. Cara seperti diatas,
git submodule foreach git checkout master
git submodule foreach git pull origin master
Atau buat pull request
dengan cara:
cd public
git push origin HEAD:refs/heads/37f62cf
Nombor 37f62cf
ialah contoh rujukan HEAD semasa dari GitHub commit.
Coba tukar branch ke master
.
git checkout master
repo already exists in the index
Bila repo masih ada di indeks walaupun telah dibuang dengan rm -r harbor
. Bila
larikan
rm -r harbor
git submodule add https://github.com/matsuyoshi30/harbor.git harbor
'rack' already exists in the index
Harus unstage harbor direktori terlebih dahulu sebelum tambahkan submodule harbor.
git rm -r harbor
git submodule add https://github.com/matsuyoshi30/harbor.git harbor
Kekunci ssh
Sekiranya ingin pakai kekunci ssh
boleh tukar di file config
di:
- .git/config
[submodule "public"]
# url = https://github.com/yusbk/yusbk.github.io.git
url = git@personal:yusbk/yusbk.github.io.git
- .git/module/public/config
[remote "origin"]
# url = https://github.com/yusbk/yusbk.github.io.git
url = git@personal:yusbk/yusbk.github.io.git
fetch = +refs/heads/*:refs/remotes/origin/*