LoginSignup
33
39

More than 5 years have passed since last update.

さくらのレンタルサーバーにGit環境を構築してみる

Last updated at Posted at 2018-10-04

前提条件

  • アカウントがtestuser
  • ウェブ公開ディレクトリ(ドキュメントルート)が/home/アカウント名/www/

とする。

また、最安のライトプランではssh接続できないので対象外となります。

サーバー情報の詳細はコチラ
https://help.sakura.ad.jp/hc/ja/articles/206053142--%E3%81%95%E3%81%8F%E3%82%89%E3%81%AE%E3%83%AC%E3%83%B3%E3%82%BF%E3%83%AB%E3%82%B5%E3%83%BC%E3%83%90-%E5%9F%BA%E6%9C%AC%E4%BB%95%E6%A7%98

ローカルリポジトリの作成

任意のディレクトリでテストというフォルダを作成する

mkdir test
cd test

ローカルリポジトリの作成

git init
touch hello.php
vi hello.php

ファイル内容を編集する。

<?php
echo 'Hello Sakura Server!';

コミットする。

git add hello.php
git commit -m 'first commit'

レンタルサーバーにSSHでアクセスする

ssh testuser@testuser.sakura.ne.jp
// パスワードが求められるので入力
testuser@testuser.sakura.ne.jp's password:*********

ユーザー名のフォルダの下にgitフォルダを作成

pwd
/home/testuser
mkdir git
cd git

リモートリポジトリの作成

git init --bare /home/junpeko/git/test.git
Initialized empty Git repository in /home/testuser/git/test.git/

ローカル環境から、リモートの登録を行う

pwd
/任意のフォルダ/test

git remote add origin ssh://testuser@testuser.sakura.ne.jp/home/testuser/git/test.git

リモートの確認

git remote
origin

OK!

リモートにpushする

git push origin master
testuser@testuser.sakura.ne.jp's password: 

リモートからさくらレンタルサーバーの公開用リポジトリを作成

cd www
pwd
/home/testuser/www
mkdir test
cd test
git init
Initialized empty Git repository in /home/testuser/www/test/.git/

リモートリポジトリを登録する

% git remote add origin /home/testuser/git/test.git
% git remote
origin

登録したリモートリポジトリよりpullする。

% git pull origin master
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/junpeko/git/test
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master

URLでアクセスして確認

<ドメイン>/test/hello.phpにアクセス
hello_php-2-2.jpg

完了です:ok_hand:

33
39
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
33
39