← 記事

2022年11月2日、宮崎にて

gitでデプロイする方法

IndieWebの大ファンとしてお伝えしたいのですが、自分のWebサイトをホスティングしてデプロイするのに、GitHubやRender、Netlifyなどのサービスは必要ありません。Linux VPSが1台あれば十分です。

  1. SSHでアクセスできるVPSを用意します。~/.sshでSSH鍵によるログインを設定します(Windowsでも使えます)。
     Host example.com
       User yourUser
       IdentityFile ~/.ssh/keyfile
       IdentitiesOnly yes
    
  2. ターミナルでssh example.comを実行します。
  3. サーバー上の好きなフォルダーでgit initを実行します。
  4. git config receive.denycurrentbranch updateInsteadを実行します。
  5. ローカルのシステムでgit add remote origin ssh://example.com:/path/to/your/repo/.gitを実行します。
  6. これでサーバーとの間でpushやpullができ、フォルダーが更新されるようになります。

このブログ記事もこの方法で公開しました。

これで解決するよくあるエラー

git configで
receive.denycurrentbranch updateInsteadを設定しないと、次のエラーが発生します。

remote: error: refusing to update checked out branch: refs/heads/master
 remote: error: By default, updating the current branch in a non-bare repository
 remote: error: is denied, because it will make the index and work tree inconsistent
 remote: error: with what you pushed, and will require 'git reset --hard' to match
 remote: error: the work tree to HEAD.

パスワード付きSSH:Windowsでパスワードを何度も入力しないようにする

こちらを参照してください。
How to run ssh-add on windows