GitHubを使わず、Laptop A/A' と Desktop B を核とした効率的な研究・開発環境の構築
手元のLaptop A/A'を「メインリモコン」、大学のDesktop Bを「正本ハブ」とし、各スパコンへ個別に、あるいは一斉にデプロイする構成です。
updateInstead 設定により、Pushした瞬間に作業ディレクトリのファイルが最新に書き換わり、そのまま計算実行が可能。git config receive.denyCurrentBranch updateInstead全てのマシンで、作業用ディレクトリを作成し、外部からのPushを許可します。
# 計算機 B, C, D, E のそれぞれで実行
mkdir -p ~/project_dir && cd ~/project_dir
git init
git config receive.denyCurrentBranch updateInstead
混乱を避けるため、既存のローカルベア設定などを一度削除します。
git remote remove origin
git remote remove all # 存在する場合のみ
Bを「正本(origin)」とし、各マシン(b, c, d, e)を個別に登録。さらに一括送信用の「all」も作成します。
# Bをメイン同期先として登録
git remote add origin univ-b:~/project_dir
# 個別送信用リモート
git remote add b univ-b:~/project_dir
git remote add c univ-c:~/project_dir
git remote add d inst-d:~/project_dir
git remote add e inst-e:~/project_dir
# 一括送信用リモート (git push all 一発で全員へ)
git remote add all univ-b:~/project_dir
git remote set-url --add --push all univ-b:~/project_dir
git remote set-url --add --push all univ-c:~/project_dir
git remote set-url --add --push all inst-d:~/project_dir
git remote set-url --add --push all inst-e:~/project_dir
git remote -v で全てのURLが正しく設定されているか確認してください。
大学にいる時は、Bからも直接他の計算機を制御できるようにします。
# Desktop B のリポジトリにて実行
git remote add c univ-c:~/project_dir
git remote add d inst-d:~/project_dir
git remote add e inst-e:~/project_dir
※ Laptop Aへの逆方向SSHは不要なため、登録しません。
特定の宛先オプションをつけてPushするためのスクリプトです。A, B 両方に配置推奨。
#!/bin/bash
# Usage: gpush [-b] [-c] [-d] [-e] [-a]
usage() { echo "Usage: gpush [-b] [-c] [-d] [-e] [-a (all)]"; exit 1; }
if [ $# -eq 0 ]; then usage; fi
targets=()
while getopts "bcdea" opt; do
case "$opt" in
b) targets+=("b") ;;
c) targets+=("c") ;;
d) targets+=("d") ;;
e) targets+=("e") ;;
a) targets=("b" "c" "d" "e") ;;
esac
done
current_branch=$(git symbolic-ref --short HEAD)
for target in "${targets[@]}"; do
# 自身がDesktop Bの場合、bへのpushはスキップ
if [[ "$target" == "b" && "$HOSTNAME" == "DesktopB_Host" ]]; then continue; fi
echo ">> Pushing to: $target ($current_branch)"
git push "$target" "$current_branch"
done
| 状況 | アクション |
|---|---|
| Aで書いたコードを保存 | git push origin main (Bへ) |
| 特定のスパコンDに送る | gpush -d |
| AとA'を同期させる | AでPushした後、A'で git pull origin main |
| Dでの修正を回収する | A(またはB)にて git pull d main → git push origin main |