Skip to content

Instantly share code, notes, and snippets.

@watari53
Created July 27, 2014 10:04
Show Gist options
  • Save watari53/87aa5a654aa05184430e to your computer and use it in GitHub Desktop.
Save watari53/87aa5a654aa05184430e to your computer and use it in GitHub Desktop.
gist and heroku install and setup

#GitとHerokuのインストールと基本的な使い方 OS Ubuntu12.04

最初のセットアップ

$ git config --global user.name "hoge"
$ git config --global user.email hogehoge.com 

コマンドのエイリアス

git config --global alias.co checkout

Gitのコミットメッセージ入力のエディタ

$ git config --global core.editor "vim -f"

最初のリポジトリのセットアップ

$ git init

gitignoreの設定

$ vi .gitignore

以下を追加

Ignore other unneeded files.
doc/
*.swp
*~
.project
.DS_Store
.idea
.secret

ファイルをGitに追加

$ git add .

ここで「.」は現在のディレクトリ (カレントディレクトリ) を指します。Gitは再帰的にファイルを追加できるので、自動的にすべてのサブディレクトリも追加されます。このコマンドにより、プロジェクトのファイルは、コミット待ちの変更が格納されている「ステージングエリア」という一種の待機場所に追加されます。ステージングエリアにあるファイルのリストを表示するには、statusコマンドを実行します。

$ git status

変更を保存

$ git commit -m "Initialize repository"

-mでコミットメッセージを入力できる

コミットメッセージの履歴を参照

$ git log

間違えてappを消してしまう

$ rm -r app
$ git status

チェックアウトすれば復元できる

$ git checkout -f
$ git status

GitHubに登録 登録後、New repositoryボタン

Repository name:first_app
Description:The first app for the Ruby on Rails Tutorial

Publicにチェック 以下のような画面が出る

Quick setup — if you've done this kind of thing before
or	
HTTP
SSH

We recommend every repository include a README, LICENSE, and .gitignore.

Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/watari53/Site.git
git push -u origin master
Push an existing repository from the command line

git remote add origin https://github.com/watari53/Site.git
git push -u origin master

Gitにアップロード

$ git remote add origin https://github.com/watari53/Site.git
$ git push -u origin master

ブランチ(Branch)

$ git checkout -b modify-README
$ git branch #確認

2つ目のコマンド (git branch) は、単にすべてのローカルブランチを一覧表示しているだけです。「」はそのブランチが現在使用中であることを表します。1番目のgit checkout -b modify-READMEコマンドで、ブランチの新規作成とそのブランチへの切り替えが同時に行われていることに注目してください。modify-READMEブランチにが付いていることで、このブランチが現在使用中であることが示されています (coエイリアスを設定した場合は、git co -b modify-READMEと入力することもできます)。

変更(Edit) トピックブランチを作成後、READMEの内容をわかりやすく書き換えてみましょう。著者の場合、デフォルトのRDocを編集するときには主にMarkdownというマークアップ言語を使用しています。拡張子を.mdにしておけば、GitHubにアップロードしたときに自動的にドキュメントがきれいに整形されます。今回はGitに付属するmvコマンド (注: Unixのmvコマンドではありません!) を使ってREADMEの拡張子を変更し、それからREADMEの内容をリスト書き換えます。

$ git mv README.rdoc README.md
$ vi README.md

コミット(commit) 変更が終わったら、ブランチの状態を確認して、commit

$ git status
$ git commit -a -m "Improve the README file"

-aフラグは慎重に扱ってください。最後のコミット後に新しいファイルを追加した場合は、まずgit addを実行してバージョン管理下に置く必要があります。
コミットメッセージは現在形で書くようにしましょう。Gitのモデルは、(単一のパッチではなく) 一連のパッチとしてコミットされます。そのため、コミットメッセージを書くときには、そのコミットが「何をしたのか」と履歴スタイルで書くよりも「何をする」ためのものなのかを書く方が、後から見返したときにわかりやすくなります。さらに、現在形で書いておけば、Gitコマンド自身によって生成されるコミットメッセージとも時制が整合します。詳細についてはGitHubに投稿された「最新のコミット方法 (英語)」を参照してください。

マージ(merge)

$ git checkout master	#ブランチを変更
$ git merge modify-README	#マージ
$ git branch -d modify-README	#ブランチの削除

git branch -D #トピックブランチ上の変更を破棄することもできる

プッシュ(push)

$ git push
$ git remote add origin https://github.com/hoge/sample_app.git
$ git pull https://github.com/hoge/sample_app.git

試しに別のマシンから対象のリポジトリ内のファイルをpullする手順

$ mkdir sample_app
$ cd sample_app
$ git init

デプロイ Herokuのセットアップ

$ vi Gemfile 以下を追記

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

本番用のgem(今回はpgとrails_12factor)をローカル環境にインストールしない

$ bundle install --without production

コミットしておく $ git commit -a -m "Update Gemfile.lock for Heroku"

Herokuのユーザ登録を行う Heroku

ここを参照し、heroku toolbeltをインストール https://toolbelt.heroku.com/

$ wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
$ heroku login
ID:passを入力

$ git clone git://github.com/---/Site.git
$ cd Site/
$ heroku create

Herokuにデプロイする

$ git push heroku master
$ heroku open	#ルーティングができていないためエラーになるが無視

Herokuコマンド

$ heroku rename abcedeaexample	#Appsの名前変更

Herokuドキュメント

http://devcenter.heroku.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment