Debian 13 trixie

Git : 共有リポジトリを作成する2025/10/10

 

複数ユーザーで利用可能な共有リポジトリを作成します。

[1] 共有用のグループを作成して、共有リポジトリを使用予定のユーザーを全て所属させておきます。
# 任意のグループ作成

root@dlp:~#
groupadd project01
# 作成したグループにユーザー追加

root@dlp:~#
usermod -aG project01 debian

root@dlp:~#
usermod -aG project01 trixie
[2] 共有用のグループに所属させた任意の一般ユーザーで共有リポジトリを作成します。
# 共有リポジトリ用のディレクトリを作成して準備した共有用グループに変更

debian@dlp:~$
mkdir project01.git

debian@dlp:~$
chgrp project01 project01.git

debian@dlp:~$
cd project01.git
debian@dlp:~/project01.git$
chmod 755 /home/debian

# 共有用の空リポジトリを作成

debian@dlp:~/project01.git$
git init --bare --shared

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint:   git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint:   git branch -m <name>
Initialized empty shared Git repository in /home/debian/project01.git/

# [--shared] オプションを付加して作成すると SGID がセットされる

debian@dlp:~/project01.git$
ll -d /home/debian/project01.git

drwxrwsr-x 7 debian project01 4096 Oct 10 08:45 /home/debian/project01.git
[3] [1] で共有用のグループに所属させた任意の一般ユーザーで確認します。
trixie@dlp:~$
mkdir work

trixie@dlp:~$
cd work
trixie@dlp:~/work$
git init

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint:   git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint:   git branch -m <name>
Initialized empty Git repository in /home/trixie/work/.git/

trixie@dlp:~/work$
git config --global user.name "Server World"

trixie@dlp:~/work$
git config --global user.email "trixie@dlp.srv.world"
# テストファイルを作成してリポジトリに反映

trixie@dlp:~/work$
echo testfile > testfile1.txt

trixie@dlp:~/work$
git add testfile1.txt

trixie@dlp:~/work$
git commit testfile1.txt -m "Initial Commit"

[master (root-commit) edd765d] Initial Commit
 1 file changed, 1 insertion(+)
 create mode 100644 testfile1.txt

trixie@dlp:~/work$
git remote add origin /home/debian/project01.git

trixie@dlp:~/work$
git config --global --add safe.directory /home/debian/project01.git

trixie@dlp:~/work$
git push origin master

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 234 bytes | 234.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To /home/debian/project01.git
 * [new branch]      master -> master
関連コンテンツ