1
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.

Git備忘録(Railsチュートリアル)

1
Last updated at Posted at 2021-03-10

背景

Railsチュートリアル(6.0)第1章で理解した内容やコマンドをまとめて備忘録にする

<前提>
・Gitインストール・セットアップは完了済
・クラウドIDEは使用しない

名前とメールをGitに設定

$ git config --global user.name "自分の名前"
$ git config --global user.email "自分のメールアドレス"

git checkoutコマンドを楽にgit coで実行できるよう設定

$ git config --global alias.co checkout

gitでパスワードを一定時間保持するように設定(86400は保持する秒数)

$ git config --global credential.helper "cache --timeout=86400"

リポジトリの作成(2種類)

$ git init
$ git init [ディレクトリ名]

プロジェクトの全ファイルをリポジトリに追加

$ git add -A

ステージングの状態を知る。

 最初はステージングという一種の待機用リポジトリに置かれ、コミットを待つ。
 安全のため、いきなりコミットしないようになっている

git status

ステージングエリアで控えている変更を本格的にリポジトリに反映

 -mはコマンドラインでコミットメッセージを直接指定するもの

$ git commit -m "Initialize repository"

 その後GithubのURLへ行き、新しくリポジトリ作成
 privateにチェックを忘れない

コミットメッセージ履歴を確認

$ git log

作業ツリー内で何かミスって、以前のコミットに戻す(コミットしてない場合)

$ git checkout -f

GitHubをリモートoriginに追加してそのリポジトリにpush

$ git remote add origin https://github.com/GitHubアカウント名/プロジェクト名
$ git push -u origin master

-uは初めてプッシュする時に使用。二回目以降は
git pushでOK

master(親)ブランチからトピックブランチ(短期間だけ使う一時的なブランチ)を作成

$ git checkout -b 作成したいブランチ名

ローカルブランチを一覧表示

$ git branch

変更が終わったら、ブランチの状態を確認

$ git status

現存するすべてのファイル(git mvで作成したファイルも含む)への変更を一括でコミット

 コミットメッセージは現在形かつ命令形で書くこと

$ git commit -a -m "コミットメッセージ"

ファイルの変更が終わったら、masterブランチに変更をマージ

$ git checkout master
$ git merge ブランチ名

ローカルブランチ削除

**・**変更をマージした後の場合(任意)
**・**変更をマージしていない場合

$ git branch -d ブランチ名
$ git branch -D ブランチ名

本番用以外のgemをインストールする

Gemの変更をGemfile.lockに反映させる

bundle install --without production

変更内容をコミット

git commit -a -m "Update Gemfile for Heroku"

herokuインストール&バージョン確認

brew tap heroku/brew && brew install heroku
heroku --version

herokuコマンドでブラウザを開かないように設定

heroku login --interactive

Herokuに新しいアプリケーションを作成

heroku create

Herokuにデプロイ

git push heroku master
(master省略可能)

Herokuコマンド一覧

heroku help

終わりに

今回はRailsチュートリアル第1章でgitについて作業した内容を書きました。

1
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
1
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?