LoginSignup
0
0

More than 3 years have passed since last update.

Git pushでXSERVERのWebsite更新をする(備忘録)

Last updated at Posted at 2020-04-04

XSERVERのWebsiteをgit push コマンドで可能にします。GitやSSH公開鍵認証を学ぶ上でもいいトレーニングになります。参考にさせて頂いたサイトの方々ありがとうございました。

環境と準備

  • Windows 10 home
  • Windows Powershell
  • gitのインストール(ローカル)
  • github登録
  • XSERVER契約

システムのイメージ

XSERVERをRemote Repositoryとして、Public_html上に作成した本番repositoryを、同サーバー別directoryに作ったbare-repositoryをそのcloneとして作成。Localからbare-repositoryにpushでbareのhooksが感知してpost-receiveが作動し、本番repositoryがpullをし、bareのデータを本番repoに持ってくるシステム。
public_html内でgit作業するリスク回避のためbare-repositoryを用意し、管理していると認識。

ステップ

  • SSH鍵作成(ローカルで用意)後々githubとXSERVERで鍵を使いまわせるから、同時pushで便利。
  • SSH config 作成
  • XSERVERにSSH接続し、gitをインストール
  • Public_htmlにgit initし、本番nonbare-repositoryを作成、git init
  • git cloneでbare-repositoryをpublic_htmlと同じ階層に作成
  • bare-repositoryのhooksにpost-receiveを作成
  • localの作業フォルダに移動し、bare-repositoryをremote-repoとして追加する。
  • localからpushテストし、public_html内で更新内容確認

githubにも同時にpushそして、pull先はgithubに設定の場合

  • githubでSSH公開鍵登録、git remote set-url --addでgithub内repoを紐づけ。(同時push)
  • git pullのリモート先をgithubにする
    1. git remote rm origin
    2. git remote add origin git@github.com:~~~~/~~~~ (SSH接続のpath)
    3. git remote set-url --add origin xsrv:~/~/~

参考URL

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0