いまさらながらGitとgithubで遊ぶ
Rails勉強会東京に行ってみて感じたことが2つある。
- みんなmacbookだよ。
- gitとかgithubは使えて当たり前。
ってなことで、gitとgithubで遊んでみる。
ちょうど、前に作ったTracのTicket数グラフ化プラグインがあるので、こいつをgithubで公開しようと思う。
こっから手順について書きますよ。
gitインストール
Downloads -
msysgit -
Git for Windows - Google Project Hosting
からダウンロードする。
落としたexeを実行してインストール完了。
途中で、cygwinから使うかdosプロンプトから使うのか選択するところがあったが、dosプロンプトにしておいた。
コマンドプロンプトからgit --help でゴー。
C:\dev\work>git --help usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|- e=GIT_WORK_TREE] [--help] COMMAND [ARGS] The most commonly used git commands are: add Add file contents to the index bisect Find the change that introduced a bug by binary search branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff Show changes between commits, commit and working tree, fetch Download objects and refs from another repository grep Print lines matching a pattern init Create an empty git repository or reinitialize an exist log Show commit logs merge Join two or more development histories together mv Move or rename a file, a directory, or a symlink pull Fetch from and merge with another repository or a local push Update remote refs along with associated objects rebase Forward-port local commits to the updated upstream head reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index show Show various types of objects status Show the working tree status tag Create, list, delete or verify a tag object signed with See 'git help COMMAND' for more information on a specific command.
オッケーです。
githubのアカウントを取る。
まずはGitHub · Social Codingで"sign up now"を押してアカウントを取る。
お金を払うと使用できる容量が増えたりPrivateのリポジトリが持てたりするらしいが、ここはfreeを選択する。
で、User name,Email Addressとかを適当に入れる。
ここで、SSH Public Key(SSH公開鍵)を登録する必要がある。これをやっておかないとgithubにpushできなくなる。
公開鍵の作り方。、
- Git Bashを起動する。(スタートメニュー→プログラム→Git に入ってるはず)
- ssh-keygen -C "登録するEmail Address" -t rsa
- どこにid_rsaファイルを作るか聞かれるのでそのままリターン。デフォルトで/c/Document and Settings/ユーザ名/.sshに作成される。
- Enter pathphraseでパスフレーズを入力。
- Entre same pathphraseで確認用にもう一度入力。
これで、/c/Document and Settings/ユーザ名/.ssh/id_rsa.pubというファイルができてるので、このファイルの中身を丸ごとコピーして、SSH Public Keyに入力する。
これで、githubのアカウントできた。
githubでリポジトリ作成
githubでアカウントを作ったら、自分のmypageに移動する。ここで、Web 上からリポジトリを作成できる。
- 「Create a Repository」をクリック
- 「Project Name」を適当に入れる。
- Descriptionに説明。 Homepage URL は自分のblog。なくてもよし。
これでリポジトリができた。
ローカルリポジトリにcommitする。
githubへの公開は、
という流れなので、まずローカルのリポジトリにcommitを行う。
適当なディレクトリを作って、そこにファイルをコピー。
git initで初期化してローカルリポジトリを作成。
git addコマンドでファイルを追加する。
$ cd /c/dev/work/git_work/tracticketgraph $ git init $ git add ./*
次に、ローカルリポジトリにcommitする。コマンドは git commti -m 'コメント'。
$ /c/dev/work/git_work/tracticketgraph $ git commit -m 'Version 0.6' Created commit b58ec17: Version 0.6 warning: LF will be replaced by CRLF in TracTicketGraph.egg-info/SOURCES.txt warning: LF will be replaced by CRLF in TracTicketGraph.egg-info/dependency_lin s.txt warning: LF will be replaced by CRLF in TracTicketGraph.egg-info/entry_points.t t warning: LF will be replaced by CRLF in TracTicketGraph.egg-info/top_level.txt 17 files changed, 1393 insertions(+), 0 deletions(-) create mode 100644 TestSql.txt create mode 100644 TracTicketGraph.egg-info/PKG-INFO create mode 100644 TracTicketGraph.egg-info/SOURCES.txt create mode 100644 TracTicketGraph.egg-info/dependency_links.txt create mode 100644 TracTicketGraph.egg-info/entry_points.txt create mode 100644 TracTicketGraph.egg-info/top_level.txt create mode 100644 TracTicketGraph.egg-info/trac_plugin.txt create mode 100644 setup.py create mode 100644 ticketgraph/__init__.py create mode 100644 ticketgraph/__init__.pyc create mode 100644 ticketgraph/htdocs/FusionChartsFree/Charts/FCF_MSColumn2DLi eDY.swf create mode 100644 ticketgraph/htdocs/FusionChartsFree/Charts/FCF_StackedColum 2D.swf create mode 100644 ticketgraph/htdocs/FusionChartsFree/JSClass/FusionCharts.js create mode 100644 ticketgraph/htdocs/ticketgraph.css create mode 100644 ticketgraph/templates/ticketgraph.cs create mode 100644 ticketgraph/ticketgraph.py create mode 100644 ticketgraph/ticketgraph.pyc
これでcommitできたよ!
githubに公開する。
じゃあ次に、ローカルリポジトリを先ほど作ったgithub上のリポジトリに公開する。
$ git remote add origin git@github.com:yuroyoro/tracticketgraph.git
これで、github上のリポジトリがoriginって名前で登録された。
では、いよいよ公開。git push origin masterでorignへpushする。
pushの際には、ssh-keygenで公開鍵を作るときに登録したパスフレーズを入力する。
$ git push origin master Enter passphrase for key '/c/Documents and Settings/ozaki/.ssh/id_rsa': Counting objects: 27, done. Compressing objects: 100% (19/19), done. Writing objects: 100% (26/26), 58.81 KiB, done. Total 26 (delta 1), reused 0 (delta 0) To git@github.com:yuroyoro/tracticketgraph.git 4394cdf..b58ec17 master -> master
これで公開完了。さっそく自分のgithubのページを見てみると、
http://github.com/yuroyoro/tracticketgraph/
できた!これで俺もgit使いだよ!