LoginSignup
3
3

More than 5 years have passed since last update.

「MBAでスクリプトを書き、リモートサーバ上で実行する」をGitで実現する

Posted at

MBA上のnon-bareリポジトリ、リモートサーバ上のbareリポジトリとnon-bareリポジトリ、で実現します。図にするとこんな感じ。

git_mba_server.png

  1. MBA上のCodaでスクリプトを書き、MBA上のnon-bareリポジトリにcommit
  2. MBA上のnon-bareリポジトリからリモートサーバ上のbareリポジトリにpush
  3. リモートサーバ上のbareリポジトリからリモートサーバ上のnon-bareリポジトリにpull
  4. リモートサーバ上でスクリプトを実行

MBA上にnon-bareリポジトリ作成

作成中のスクリプトがあるディレクトリに移動し、リポジトリを作成します。

$ cd ~/security-tweet-bot
$ git init

作成中のスクリプトをaddし、commitします。

$ git add tweet-bot.rb
$ git commit -m "initial commit"

リモートサーバ上にbareリポジトリ作成

リモートサーバ上のbareリポジトリ用のディレクトリを作成、bareリポジトリを作成します。

$ mkdir ~/git/security-tweet-bot.git
$ cd ~/git/security-tweet-bot.git
$ git --bare init

MBA上のnon-bareリポジトリのディレクトリに移動し、リモートサーバ上のbareリポジトリにpushします。

$ cd ~/security-tweet-bot
$ git remote add origin [リモートサーバのユーザ名]@[リモートサーバのアドレス]:git/security-tweet-bot.git
$ git push origin master

これで、リモートサーバ上のbareリポジトリにpushされました。

リモートサーバ上のbareリポジトリをcloneして、リモートサーバ上にnon-bareリポジトリ作成

リモートサーバ上のnon-bareリポジトリ用のディレクトリに移動し、cloneします。
ローカルホストにSSH接続できるようにしておく必要があります。

$ cd  ~/security-tweet-bot
$ git clone localhost:/Users/nekotricolor/git/security-tweet-bot.git/

リモートサーバ上のbareリポジトリからリモートサーバ上のnon-bareリポジトリにpull

これで、Codaで変更したスクリプトをcommit→リモートサーバのbareリポジトリにpush→リモートサーバ上のnon-bareリポジトリでpullすれば、目標達成です。

MBA上で:

$ git commit
$ git push origin master

リモートサーバ上のnon-bareリポジトリ用のディレクトリで:

$ git pull

参考記事

3
3
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
3
3