over 3 years ago

備註:ROR TUTORIAL (3RD ED.) Chapter 1 + RailsFun.tw 新手教學_day2 的整理

  1. 這邊的步驟,一台電腦只要設一次:

    $ git config --global user.name "Your Name"
    $ git config --global user.email your.email@example.com
    $ git config --global push.default matching
    $ git config --global alias.co checkout
  2. 首先要新建一個repo

    $ git init
    $ git init --bare prodject.git

    ps 這邊跟JC大講解的不一樣:RailsFun.tw 新手教學_day2 HD
    4:50 JC大:應該用 'git init --bare prodject.git'

  3. 把所有的檔案都夾到repo裡面去

    $ git add -A

    實際上,都還留在staging area,然後要commit跟給附註(-m)才能夠上傳。

  4. 用git status來看有什麼處在pending的改變

    $ git status
  5. -m 是用來寫附註的:

    $ git commit -m "Initialize repository"
  6. 設定好Bitbucket的帳號
    Public Key

    Listing 1.11: Printing the public key using cat.
    $ cat ~/.ssh/id_rsa.pub
  7. 設定遠端Bitbucket的repo origin,然後把本地端的東西上傳到遠端的repo
    每個新專案都要新增一個專屬的repo (Create a new repository),然後才可以上傳檔案。
    第一次上傳要使用$ git push -u origin --all,之後只要用git push
    Listing 1.12: Adding Bitbucket and pushing up the repository.
    設定遠端Bitbucket的repo origin

    $ git remote add origin git@bitbucket.org:<username>/hello_app.git


    $ git push -u origin --all # pushes up the repo and its refs for the first time

    The commands in Listing 1.12 first tell Git that you want to add Bitbucket as the origin for your repository, and then push your repository up to the remote origin. (Don’t worry about what the -u flag does; if you’re curious, do a web search for “git set upstream”.) Of course, you should replace with your actual username. For example, the command I ran was

    $ git remote add origin git@bitbucket.org:mhartl/hello_app.git
  8. 記得做任何比較大的改變之前,都要新增一個branch。
    checkout -b可以新增一個new branch,同時switch去這個new branch

    $ git checkout -b modify-README
    Switched to a new branch 'modify-README'
  9. 如果只是一些小改變,可以直接用git commit -a -m,可是如果有新增檔案,就必須先用git add -A然後再用git commit -m

  10. merge要先由branch去合併master,然後再由master去合併branch

    JC講的:RailsFun.tw 新手教學_day2 HD

  11. -D是可以不用merge 就可以暴力把branch刪掉

    git branch -D topic-branch
  12. 有新的變更,就再用一次git push上傳到Bitbucket

    $ git push
  13. 版本(Git)做好之後,可以開始部署(deploy到Heroku)去Production了。

  14. Heroku 使用 PostgreSQL database

    :production 要用pg (PostgreSQL)

    group :production do
    gem 'pg',             '0.17.1'
    gem 'rails_12factor', '0.0.2'

    Note also the addition of the rails_12factor gem, which is used by Heroku to serve static assets such as images and stylesheets. Finally, be sure to incorporate the changes made in Listing 1.5 preventing the sqlite3 gem from being included in a production environment, since SQLite isn’t supported at Heroku:


    group :development, :test do
    gem 'sqlite3',     '1.3.9'
    gem 'byebug',      '3.4.0'
    gem 'web-console', '2.0.0.beta3'
    gem 'spring',      '1.1.3'

    雖然加上without production,不會在local端install pg跟rails_12factor這兩個gem,不過其實是更新到Gemfile.lock

    $ bundle install --without production
  15. 再把剛剛做的事情在commit一下

    $ git commit -a -m "Update Gemfile.lock for Heroku"
  16. Heroku setup

  17. 確定有沒有灌過heroku CLI跟Heroku Toolbelt

    $ heroku version
  18. 登入跟輸入SSH key
    Once you’ve verified that the Heroku command-line interface is installed, use the heroku command to log in and add your SSH key:

    $ heroku login
    $ heroku keys:add

    Finally, use the heroku create command to create a place on the Heroku servers for the sample app to live (Listing 1.15).

  19. 新建一個網址

    $ heroku create
  20. 在push到heroku master,就好了

    $ git push heroku master
  21. push之後,記得要migrate the production database (chapter 2 才提到這件事情 2.3.5 Deploying the toy app)

    $ heroku run rake db:migrate
  22. 如何在上傳Heroku之後,還可新增使用者跟管理者

    $ heroku run rails console

    Getting Started with Rails 3.x on Heroku

← 前端向上計畫: Day 3 RWD 20160303 ROR TUTORIAL (3RD ED.) Ch3 Mostly static pages →