※リモートサーバー上でgitコマンドを使用するため、gitが使える共用サーバーでなければ以下の作業はできない。
ここでは、さくらのレンタルサーバー(スタンダード)でやってみた。
ホームディレクトリ直下にreposディレクトリを作成し、その中にGitリポジトリを作ることにする。
準備
公開鍵認証でsshログインできるようにしておく。
ローカルのユーザー名はpgenで、秘密鍵はローカルの~/.ssh/secret_key.ppkにあるものとする。
サーバー側の作業
リポジトリ用ディレクトリを作成し、空のリポジトリ(sample.git)を作成する。
$ mkdir ~/repos $ cd ~/repos $ mkdir sample.git $ cd sample.git $ git init --bare
ローカルでの作業
~/.ssh/configに以下の内容を追加する。
Host sakura User さくらのレンタルサーバーのID IdentityFile ~/.ssh/secret_key.ppk HostName さくらのレンタルサーバーのID.sakura.ne.jp
何かファイルを作成してコミットする。
$ echo 'Hello,Git!' > hello $ git add hello $ git commit -m 'made hello'
リモートブランチの設定。
$ git remote add origin さくらのレンタルサーバーのID@sakura:repos/sample.git
リモートリポジトリにプッシュする。
$ git push origin master
Enter passphrase for key '/home/pgen/.ssh/secret_key.ppk':
Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To さくらのレンタルサーバーのID@sakura:repos/sample.git
* [new branch] master -> master
リポジトリを取り出してみる
別の端末を開き、今プッシュしたリポジトリを取り出してみる。
$ git clone さくらのレンタルサーバーのID@sakura:repos/sample
Cloning into 'sample'...
Enter passphrase for key '/home/pgen/.ssh/secret_key.ppk':
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.
$ ls sample
hello
よし、成功。
以上をふまえて、次回はVirtualBox上にGitリポジトリサーバーを建てたいと思います。
参考記事
さくらのレンタルサーバ スタンダード
