LoginSignup
0
4

More than 3 years have passed since last update.

コピペ用!git+herokuデプロイまでの忘備録

Last updated at Posted at 2020-04-29

gitでローカルリポジトリからリモートリポジトリにpushするまでのコマンドとコマンド毎の各種エラーを解説

//gitの設定を削除
rm -rf .git

gitでローカルリポジトリからリモートリポジトリにpushするまでワークフローはだいたいこんな感じ

//ローカルリポジトリとして登録
git init

//リポジトリの初期設定
git config --global user.email メールアドレス
git config --global user.name ユーザ名

//originのリモートリポジトリ登録
git remote add origin https://github.com/ユーザ名/リポジトリ名

//指定のファイルをステージングエリアへ
git add -A

//ステージングエリアのファイルを、ローカルリポジトリに確定
git commit

//ローカルリポジトリのファイルをリモートリモジトリにアップロード
git push origin master
//上記のコマンドを無理やりpush
git push -f origin master

それでは一連の流れを再現するコマンドを学んだことで、続いて各コマンドの深い所まで学んでいきましょう。


指定のファイルをステージングエリアへ移動

//指定のファイルをステージングエリアへ
git add

//オプションの解説
//配下のファイル全てを指定
git add -A

//配下のファイル全てを指定
git add .

ステージングエリアのファイルを、ローカルリポジトリに確定

//ステージングエリアのファイルを、ローカルリポジトリに確定
git commit -m "1st"

//オプションの解説
//配下のファイル全てを指定
git commit --amend

//ローカルリポジトリのファイルをリモートリモジトリにアップロード

git push origin master

git push origin masterで発生するエラー一覧

error: failed to push some refs to 'https://github.com/repogitori.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.

参照:GitHubにpushする時にエラー:一部の参照をプッシュできませんでしたと表示されてpushできない時

上記のエラーの解決法として「git push -f origin master」で無理やりpushすることが可能。

//git commit をリセットする。
git riset

//コミット後にブランチを消す、コミットを一つにまとめる、
git rebase -i

リモートリポジトリ名前指定なし、push
git push -f origin HEAD

//git addをキャンセル、リセットする。
git stash

gitコンフリクト解消


herokuデプロイコマンド集

ヘロクにログインする

heroku login

ヘロクのアップ置き場を作る。

heroku create リポジトリ名(かぶるとエラー)

(例)

ヘロクのアップ置き場を作る。(ララベルオプション付き)

heroku create リポジトリ名 --buildpack heroku/php

ヘロクのアップ置き場を作る。(レイルズオプション付き)

heroku create リポジトリ名 --buildpack heroku/ruby

herokuにデプロイ

git push heroku master

railsプロジェクトを本番環境(heroku)にマイグレーション

heroku run rails db:migrate

laravelプロジェクトを本番環境(heroku)にマイグレーション

heroku run php artisan migrate


railsプロジェクトをheroku用に書き換え

1.Gemfileの設定
2.config/datebase.ymlの設定
3.config/environments/production.rbの設定

1.Gemfileの設定
sqlite3を以下のように上書きしよう

gem 'sqlite3', groups: %w(test development), require: false
gem 'pg', groups: %w(production), require: false

2.config/datebase.ymlの設定

config/datebase.yml
production:
#半角スペース2個分の空白を開ける
  <<: *default
  adapter: postgresql
  encoding: unicode
  pool: 5

3.config/environments/production.rbの設定

config/environments/production.rb
#デフォルトでfalseとなっている以下の箇所をtrueに変更
  config.assets.compile = true


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