0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby on Rails チュートリアル 第1章②

0
Last updated at Posted at 2020-05-03

○この記事の要点
「第1章 ゼロからデプロイまで」の途中から最後までの実施内容メモ
思ったことなどのメモ

○内容
■Gitによるバージョン管理
 ・初期設定 git init
 ・リポジトリに追加 git add -A
 ・コミット git commit
 (git commitはローカルマシン上までの反映。git pushでリモートリポジトリへの反映)
 ・バージョン管理のメリット
  ・誤って削除しても元に戻せる
  ・他人と共有できる
  ・好きなバージョンに戻せる

■Bitbucketによるリモートリポジトリ管理
 ・Bitbucketのユーザ登録(https://bitbucket.org/account/signup/)
 ・公開鍵の作成(https://git-scm.com/book/ja/v2)4.3 Gitサーバー - SSH 公開鍵の作成 参照
 ・Bitbucketへ公開鍵の登録
  Bitbucketの自分のページの左下にあるEボタン⇒personalsetting⇒SSH鍵⇒鍵を追加。keyにat ~/.ssh/id_rsa.pub で表示されたssh-rsaをペースト
 ・リポジトリの作成
  Bitbucketでcreate repository
ubuntu:~/environment/hello_app (master) $ git remote add origin git@bitbucket.org:ユーザ名/hello_app.git
git push -u origin --all ※1 エラー発生

エラー
ubuntu:~/environment/hello_app (master) $ git push -u origin --all
・・・
省略
error: failed to push some refs to 'git@bitbucket.org:ユーザ名/hello_app.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

対処:理由は不明だったが、ローカルリポジトリとリモートリポジトリで差異があるから?
ググって強制的にプッシュ。解決
$ git push -f origin master

※GitHubではなく、Bitbucketを利用する理由
⇒どちらもGitリポジトリのホスティングと共同作業を行うことができ、リポジトリの表示や検索を行いやすくできる。GitHubは「リポジトリを一般公開する場合は無料、公開しない場合は有料」なのに対し、Bitbucketは「共同作業者が一定数以下ならリポジトリを公開しなくても無料、共同作業者が一定数を超えると有料」。本チュートリアルではWebアプリケーションの様々なコードを扱うため、全てのリポジトリがデフォルトで非公開になっている方がセキュリティ上安心して取り組めるため、Bitbucketを利用。※2019年1月からGitHubの非公開型レポジトリが無料になったため、本チュートリアルでも現在のBitBucketからGitHubに切り替える可能性あり。

■Gitの使い方(branch、edit、commit、merge)
ブランチの作成~masterへのマージ
・git checkout -b modify-README modify-READMEというブランチを作成
・git branch 存在するローカルブランチの表示。*がついているのが現在卯使用中のブランチ
・git commit -a -m "コミットメッセージ" ブランチ内でコミット
・git checkout master マスターブランチに切り替え
・git merge modify-README modify-READMEブランチの変更内容をマージ
・git branch -d modify-README modify-READMEブランチの削除(削除は必須ではない)
・git push  マスターへプッシュ

■Herokuを利用したデプロイ
・Herokuで利用するPostgreSQLデータベースのインストール
・Gemfileの追記 ※解説には以下の2点が記載されているが、事前の書き換えで1点目はすでに記載

Gemfileファイル
group :development, :test do
  gem 'sqlite3', '1.3.13'  ←この1行
  gem 'byebug',  '9.0.6', platform: :mri
end
group :production do ←ここから3行
  gem 'pg', '0.20.0'
end

・bundle installの実行
$ bundle install --without production
・Gemfileの変更内容コミット
git commit -a -m "Update Gemfile for Heroku"
・Herokuのアカウントを新規作成
・IDEでHerokuのインストール
source <(curl -sL https://cdn.learnenough.com/heroku_install)
・Herokuにログイン、SSH鍵の追加

SSH鍵の追加
heroku login --interactive
heroku keys:add

・Herokuサーバーにサンプルアプリケーションの実行場所を作成
Herokuのサイトから、登録されたアプリケーション実行場所が表示されるようになる
・Herokuにデプロイする
git push heroku master
・Webサイトを見る
heroku createで作成されたURLを開くと、表示される

■メモ(アプリの修正とデプロイ手順)
(1)IDEでファイルの修正
(2)git commit
(3)git push
(4)git push heroku
※試してみたが、(3)git pushを飛ばした以下の順番でも、Herokuに載せたアプリは
修正後の動作になったが、Bitbucketから見たリモートリポジトリには変更が反映されていなかったので、実施することを推奨
(1)IDEでファイルの修正
(2)git commit
(4)git push heroku

■感想
・GitHubは利用したことがあったが、Bitbucketは初利用。まだ触ったばかりなので、良さは全然わかっていない。これから。
・Herokuはアプリケーションサーバだと思うけど、gitのプッシュと連携していていい感じ。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?