Gitサーバでの運用

外部VPSにGitサーバ用として使おうとインストールしていたがそのまま放置していたので
今作成中のサービスの管理をしようと思いその作業ログ

ユーザ:gitであらかじめ環境を作っておいた

サーバ側作業

$mkdir /home/hoge/project.git
$cd /home/hoge/project.git
$git --bare init
git init の --bare オプション:作業ディレクトリのない空のリポジトリを初期化する

クライアント側作業(作業ディレクトリ内の作業)

$git init
$git add .
$git commit -m "initial commit"
$git remote add origin ssh://git@{ホスト名またはIPアドレス}:{sshポート番号}/home/hoge/project.git
$git push origin master
>Counting objects: 545, done.
>Compressing objects: 100% (535/535), done.
>Writing objects: 100% (545/545), 29.15 MiB | 1.86 MiB/s, done.
>Total 545 (delta 136), reused 0 (delta 0)
>To ssh://git@{hostname}:{#port}/home/hoge/project.git
> * [new branch] master -> master

これで完了。

$git remote add origin ssh://*****
sshポート番号の指定ミスで、pushに失敗下場合、再度同じコマンドを入れると
fatal: remote origin already exists.
となるのでその場合は、

$git remote rm origin

で削除後、再度 git remote add *** を実行すれば良い