プログラム
1
現在ローカルで作成中のウェブアプリ(Rails アプリ)を GitHub でバージョン管理しようと思った時にちょっと躓いたのでメモを残しておきます。
ローカルのプロジェクトの管理をGitHub に移行してみる
現状整理
まずは今の状態を整理すると以下の様な感じです。
- 新しく Ruby On Rails のプロジェクトをローカルで作成した
- いくつか変更は行いましたが、基本は rails new した直後くらい
- このプロジェクトを GitHub でバージョン管理を行いたい
Rails の話だけではなく、多分普遍的に利用できる情報だと思います。
GitHub にレポジトリを作成して手順通りにやってみた
- GitHub(https://github.com/)を開いて Repositories の『New』を選択する
- ユーザ登録の手順は省略しています
- Repository の作成はヘッダーの『+』や左カラムの Repositories から可能です
- 必要な項目を埋めて『Create repository』する
- Repository name は必須
- タイプは Public と Private がありますが、見られて困らなければ Public で
- Rails の場合は README や .gitignore が存在するはずなので、そのあたりは省略
- レポジトリ作成後のインストラクションに従ってみる
- 「…or push an existing repository from the command line」がローカルにすでに存在する物を追加するケースに該当する
- この思考がすでに間違っている
- 手順としては以下の様な形で書かれている
$ git remote add origin https://github.com/[user name]/[repository name].git $ git push -u origin master
- 実際に実行すると以下の様にエラーが出た
error: src refspec master does not match any. error: failed to push some refs to 'https://github.com/[user name]/[repository name].git'
エラーの解決方法
- そもそもローカルプロジェクトが git 管理になっていない
- git init を実行していない
- git 管理していないということは git push するべきものも存在しない
- ということで、以下のコマンドで解決した
$ git init $ git remote add origin https://github.com/[user name]/[repository name].git $ git add -A $ git push -u origin master Username for 'https://github.com': [user name を入力] Password for 'https://vertical-axis@github.com': [password を入力]
- これでちゃんと GitHub 管理下に入ったはず
- 「…or push an existing repository from the command line」じゃなくて、「…or create new repository on the command line」を参考にするのが正解だった、というおバカなオチでした
補足
その後、GitHubへのアクセスでエラーが出るようになってしまったので、それに対処した話へのリンクを貼っておきます。