2022年11月2日、宮崎にて
gitでデプロイする方法
IndieWebの大ファンとしてお伝えしたいのですが、自分のWebサイトをホスティングしてデプロイするのに、GitHubやRender、Netlifyなどのサービスは必要ありません。Linux VPSが1台あれば十分です。
- SSHでアクセスできるVPSを用意します。~/.sshでSSH鍵によるログインを設定します(Windowsでも使えます)。
Host example.com User yourUser IdentityFile ~/.ssh/keyfile IdentitiesOnly yes - ターミナルで
ssh example.comを実行します。 - サーバー上の好きなフォルダーで
git initを実行します。 git config receive.denycurrentbranch updateInsteadを実行します。- ローカルのシステムで
git add remote origin ssh://example.com:/path/to/your/repo/.gitを実行します。 - これでサーバーとの間で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