ハイパーニートプログラマーへの道

頑張ったり頑張らなかったり

Rails Tutorial Chapter1をやる Nitrous.ioからBitbucketにリポジトリも作ってみる

Frontmatter | Ruby on Rails Tutorial (3rd Ed.) | Softcover.io

Ruby on Rails Tutorialをやり始めたのですが、Chapter 1:From zero to deployはまあ基本的なことなのでスンスーンと進むかと。
環境はNitrous.ioです。

Nitrous.ioからbitbucketにgitリポジトリを作成する。 - Qiita

こちらの記事にもあるように、Nitrous.ioからBitbucketリポジトリを作ることは可能なようですので、そこらへんを。

Gitの設定

とりあえずNitrous.ioのコンソール上でこのように

$ 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

aliasでcheckoutcoと設定。いつも使ってる環境でもそう設定しようかなあ。

Rails serverについて

Nitrous.ioのRailsを4.2.0にアプデした時にちょっと。前記事にも書いたのですけど

Nitrous.ioでRails4.2.0にアプデ、からのrails sでアクセスできないとき - ハイパーニートプログラマーへの道

rails -b 0.0.0.0 -p 4000と打たなきゃならん・・・のか?(めんど

というわけでNitrousでの環境は

Rails version    4.2.0
Ruby version    2.1.1-p76 (x86_64-linux)
RubyGems version    2.2.2

あとはhello world!してgit initしていって・・・と初歩的な事が進んでいきます。

1.4.3 Bitbucket

アカウント作成後、右上のアバターをクリックし、アカウントの管理>SSHキー>鍵を追加

Nitorousは右上にPublic Keyがあるのだが、コピペできん?

f:id:noriyo_tcp:20150204045755p:plain

Boxに入ってコンソールから

cat ~/.ssh/id_rsa.pub
# または
cat ~/.ssh/id_rsa.pub | pbcopy

アカウントの管理>SSHキー>鍵を追加の画面でペーストする。

新規リポジトリ作成

f:id:noriyo_tcp:20150204050109p:plain

「これはプライベートリポジトリです」に必ずチェックを入れる。使用する言語はもちろんRubyを選択しときました。

その後の画面

f:id:noriyo_tcp:20150204050226p:plain

Command line>I have an existing projectを選択すると、ご丁寧に説明が現れる。

Nitrous.ioのコンソール上のプロジェクトをremote add

git remote add origin git@bitbucket.org:YOUR Bitbucket UESRNAME/hello_app.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags

やり方書いてくれているのは楽ですね。これでNitrous.ioからBitbucketへプッシュできると。

左下の「ソース」から、プロジェクトが登録されているのがわかる。

f:id:noriyo_tcp:20150204050523p:plain

README.rdoc to README.md

BitbucketはREADME.rdocを受け付けていないようなのでマークダウン形式に変える。これもチュートリアルではgitを使ってみるそうです。

$ git checkout -b modify-README

変更用のブランチを作る。

$ git mv README.rdoc README.md 

gitバージョンのmvを使うそうな。

vi README.md

こう書き込んでみる

# Ruby on Rails Tutorial: "hello, world!"

This is the first application for the
[*Ruby on Rails Tutorial*](http://www.railstutorial.org/)
by [Michael Hartl](http://www.michaelhartl.com/).

Commit

$ git status                                                                               
# On branch modify-README                                                                                                                                        
# Changes to be committed:                                                                                                                                       
#   (use "git reset HEAD <file>..." to unstage)                                                                                                                  
#                                                                                                                                                                
#       renamed:    README.rdoc -> README.md                                                                                                                     
#                                                                                                                                                                
# Changes not staged for commit:                                                                                                                                 
#   (use "git add <file>..." to update what will be committed)                                                                                                   
#   (use "git checkout -- <file>..." to discard changes in working directory)                                                                                    
#                                                                                                                                                                
#       modified:   README.md                                                                                                                                    
#                                                                                                                                                                
$ git commit -am "Improve the README file"                                                 
[modify-README e20a131] Improve the README file                                                                                                                  
 1 file changed, 5 insertions(+)                                                                                                                                 
 rename README.rdoc => README.md (71%)

あとはmasterにmergeしてgit push

modify-READMEブランチは削除して良いと。


知らなかったので・・・。

File deleteしても大丈夫

例えば、ファイル消しちゃったやべー、という場合でもあくまでworking tree上での変更なので、コミット前ならなんとかなる。

checkout -fでアンドゥ

Example

$ git checkout -f
$ git status
# On branch master
nothing to commit (working directory clean)
$ ls app/controllers/
application_controller.rb  concerns/