今回の環境: Debian GNU/Linux 7.8 wheezy
$ uname -mrsv
Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u1 x86_64
$ cat /etc/debian_version
7.8
リポジトリ管理用の git ユーザーをつくる
まず、 root 権限でリポジトリを管理するための git ユーザーを作成する。
パスワードはリポジトリにアクセスするのに必要なのでちゃんと覚えておく。
# adduser git
リポジトリをつくる (リモートリポジトリとして使う)
複数のリポジトリをまとめて管理したいので、作成した git ユーザーでリポジトリ置き場をつくる。
リポジトリを作る場所は、 git ユーザーが読み書き権限のあるディレクトリでないと、 push 時にリポジトリを更新できなくてエラーになるので注意。
$ mkdir repos
$ cd repos/
git init --bare でリポジトリを作る。
$ mkdir aaa.git
$ cd aaa.git/
$ git --bare init
Initialized empty Git repository in /home/git/repos/aaa.git/
$ ls -la
合計 40
drwxr-xr-x 7 git git 4096 2月 2 21:39 .
drwxr-xr-x 3 git git 4096 2月 2 21:39 ..
-rw-r--r-- 1 git git 23 2月 2 21:39 HEAD
drwxr-xr-x 2 git git 4096 2月 2 21:39 branches
-rw-r--r-- 1 git git 66 2月 2 21:39 config
-rw-r--r-- 1 git git 73 2月 2 21:39 description
drwxr-xr-x 2 git git 4096 2月 2 21:39 hooks
drwxr-xr-x 2 git git 4096 2月 2 21:39 info
drwxr-xr-x 4 git git 4096 2月 2 21:39 objects
drwxr-xr-x 4 git git 4096 2月 2 21:39 refs
リポジトリをローカルにクローンする
自分のアカウントでログインし、先に git のユーザー設定をしておくのが無難。
$ git config --global user.name "Nick Labadie"
$ git config --global user.email nick@localhost
$ cat ~/.gitconfig
[user]
name = Nick Labadie
email = nick@localhost
git ユーザーで作成したリポジトリをリモートとして扱う。自分のアカウントで、ローカルにクローンする。
$ git clone git@localhost:/home/git/repos/aaa.git
Cloning into 'aaa'...
git@localhost's password:
warning: You appear to have cloned an empty repository.
$ cd aaa/
クローンしたローカルリポジトリにファイルを追加してみる。
$ echo "this is readme" > README.txt
$ git add .
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: README.txt
#
$ git commit -m "1st commit"
[master (root-commit) ac4307a] 1st commit
1 file changed, 1 insertion(+)
create mode 100644 README.txt
ローカルリポジトリの更新内容をリモートリポジトリに push する。このときパスワードを聞かれるので、 git ユーザーのパスワードを入力する。
$ git push origin master
git@localhost's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 222 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@localhost:/home/git/repos/aaa.git
* [new branch] master -> master
本当は "git" 以外のユーザーをリポジトリ管理アカウントにしたかったけど、やり方がわからなかったので今回はパス。
-
ref.
- Git - サーバーのセットアップ
tags: git debian
Posted by NI-Lab. (@nilab)