ソースコード管理をする(管理者編 新規プロジェクト作成)

Githubネタばかりですが、諸事情にて似たようなネタで再度書きます^ ^;
今回はXCodeではなく、通常のUnix/Linux環境を想定しています。


全体の流れはこんな感じ。

  1. ローカルでブランチ作成
  2. Githubリポジトリ作成
  3. ローカル・リポジトリGithubにpush


1. ローカルでブランチ作成


先日AWS EC2上に作成したhello worldGithubにあげましょう!


express+ejsでhello world.
http://d.hatena.ne.jp/takuto1981/20111230/1325226921


最初はgit環境は当然ありません。

[ec2-user@ip-10-117-93-66 helloworld]$ git branch
fatal: Not a git repository (or any of the parent directories): .git
[ec2-user@ip-10-117-93-66 helloworld]$ ls -a
. .. app.js node_modules npm-debug.log package.json public routes views


git branchは、ローカルにあるブランチ環境を調べるコマンドです。



詳細は、以下参照^ ^


ソースコード管理をする(ユーザー編)
http://d.hatena.ne.jp/takuto1981/20111231/1325297172



では、git環境作ります。
ローカルにリポジトリを作るコマンドはgit initです。

[ec2-user@ip-10-117-93-66 helloworld]$ git init
Initialized empty Git repository in /home/ec2-user/helloworld/.git/
[ec2-user@ip-10-117-93-66 helloworld]$ git branch
[ec2-user@ip-10-117-93-66 helloworld]$ ls -a
. .. .git app.js node_modules npm-debug.log package.json public routes views


こんだけ。簡単ですね^ ^
git環境を作ったので、git branchでリポジトリが無いよと言われることもなくなりました。


さて、まずはどのファイルをgitが管理するファイルにするかを決めます。
ファイルを指定してgit addするだけです。
今回はhelloworldディレクトリ以下の全てを対象とします。

[ec2-user@ip-10-117-93-66 helloworld]$ git add .
[ec2-user@ip-10-117-93-66 helloworld]$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: app.js
# new file: node_modules/.bin/express
# new file: node_modules/ejs/.gitmodu



# new file: views/index.ejs
# new file: views/layout.ejs
#


gitの管理対象を決めたので、それをローカル・リポジトリに教えてあげます。
git commitでローカル・リポジトリに更新を通知します。

[ec2-user@ip-10-117-93-66 helloworld]$ git commit
[master (root-commit) 10f8634] 新規作成。
Committer: EC2 Default User
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

git config --global user.name "Your Name"
git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

git commit --amend --reset-author

254 files changed, 19499 insertions(+), 0 deletions(-)
create mode 100644 app.js
create mode 120000 node_modules/.bin/express



create mode 100644 views/index.ejs
create mode 100644 views/layout.ejs


これも前回説明した通りですが、commitの際はエディタが開き、変更点の記述を求められます。
後で何を変更したかの重要な情報なので、面倒がらずにちゃんと書くようにしましょう^ ^


で、git branchでmasterが作成されていることが確認出来れば完了!

[ec2-user@ip-10-117-93-66 helloworld]$ git branch
* master

2. Githubリポジトリ作成


これは、以下の手順1と2が全く同じなので、参照下さい。


XCode+Githubソースコード管理 (管理者編)
http://d.hatena.ne.jp/takuto1981/20120101/1325409634
> 1. Githubに新規リポジトリを作成
> 2. ローカルとGithub秘密鍵と公開鍵を作成


今回はnode-helloworldというプロジェクト名です。
gitのアドレスは、以下の通り。

github.com:takuto1981/node-helloworld.git


3. ローカル・リポジトリGithubにpush


まずはリモート・リポジトリを登録してあげます。

[ec2-user@ip-10-117-93-66 helloworld]$ git remote
[ec2-user@ip-10-117-93-66 helloworld]$ git remote add origin git@github.com:takuto1981/node-helloworld.git
[ec2-user@ip-10-117-93-66 helloworld]$ git remote
origin


で、push!

[ec2-user@ip-10-117-93-66 helloworld]$ git push -u origin master
Counting objects: 314, done.
Compressing objects: 100% (276/276), done.
Writing objects: 100% (314/314), 207.35 KiB, done.
Total 314 (delta 14), reused 0 (delta 0)
To git@github.com:takuto1981/node-helloworld.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.


Githubで確認してみると・・・




出来た!