heteml で Git を使ってみる

heteml というレンタルサーバで Git が使えるようになりました。
早速試してみます。

$ git --version
git version 1.6.6.1


version は 2010-01-21 にリリースされた 1.6.6.1 です。
ビルドもしなくて新しい Git が使えるのはさくっと使えるのはいいですね。


まず、はじめにデフォルトのユーザ名とメールアドレスを登録します。

$ git config  --global user.email "Your email"
$ git config --global user.name "Your name"


ついでに色の設定もします。

$ git config --global color.ui auto


さらにエイリアスの設定もします。
これで commit と入力せずに ci だけでよくなります。(他のも同様に)

$ git config --global alias.ci commit
$ git config --global alias.co checkout
$ git config --global alias.st status -a
$ git config --global alias.di diff


これによって、ユーザのデフォルトの設定が ~/.gitconfig に保存されます。
デフォルトの値を確認するには ~/.gitconfig を開くか、

$ git config --global --list


を実行して確認します。
ではリポジトリを作成してみます。

$ mkdir myproject
$ cd myproject
$ git init
Initialized empty Git repository in /path/to/myproject/.git/


(実際の /path/to は /home/sites/heteml/users**/k/o/h/[Your Heteml Account]/ のような感じになります。 $ pwd を実行して確認してください。)
これでリポジトリが作成されました。
試しにファイルを作成します。

$ touch index.html
$ git st
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       index.html
nothing added to commit but untracked files present (use "git add" to track)
$ git add .
$ git st
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   index.html
#
$ git ci -m 'first commit';
[master (root-commit) a81411e] first commit
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 index.html


これでコミットを実行しました。
こうしてどこのディレクトリもそのままリポジトリになります。


heteml に空のリポジトリを作成してローカルから push する


例えばローカルで MacLinux を使っていると想定します。


- heteml 側

$ mkdir repos
$ cd repos
$ mkdir myproject.git
$ cd myproject.git
$ git init --bare --shared=true


として空の共有リポジトリを作成します。


- ローカル

$ mkdir myproject
$ cd myproject
$ git init
$ git remote add origin ssh://[Your Heteml Account]@[Your Heteml SSH Server]:2222/path/to/repos/myproject.git
$ touch a.txt
$ git add .
$ git ci -a -m 'inital import';
$ git push origin master
-----------------------------------------------------
--***-------------------------------------------***--
--***---------------***-------------------------***--
--***---------------******----------------------***--
--********-********-******-********-***********-***--
--********-***--***-***----***--***-***********-***--
--***--***-********-***----********-***-***-***-***--
--***--***-***------******-***------***-***-***-***--
--***--***-********-******-********-***-***-***-***--
-----------------------------------------------------
[Your Heteml Account]@[Your Heteml SSH Server]'s password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 204 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)


としてリポジトリ上に変更を反映することができました。
これでローカルで開発しながら、FTP を使わずに変更を反映させることができます。


heteml のリポジトリからローカルに pull する


次は今作成したリポジトリから myproject2 という名前で複製します。

$ git clone ssh://[Your Heteml Account]@[Your Heteml SSH Server]:2222/path/to/repos/myproject.git ./myproject2


heteml と Github を連携する


heteml にあるファイルを Github で公開しようと思ったのですが、
ssh コマンドが heteml から使えないため、使うことができません。
public の リポジトリを git clone をすることはできますが、
Github に対して push をすることは現状ではできません。

↑すぐ対応してもらって ssh コマンドが使えるようになったので、
push が可能になりました。