Ubuntu 24.04
Sponsored Link

Git : Create Shared Repositories2024/07/24

 

Create Shared Repositories which some users can use.

[1] Create a group for share and set users in the group.
# create a group

root@dlp:~#
groupadd project01
# add users to the group

root@dlp:~#
usermod -aG project01 ubuntu

root@dlp:~#
usermod -aG project01 noble
[2] Create a shared repository with a user.
# create a directory for repository and change group

ubuntu@dlp:~$
mkdir project01.git

ubuntu@dlp:~$
chgrp project01 project01.git

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

# set empty share repository

ubuntu@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/ubuntu/project01.git/

# with [--shared] option, SGID is set like follows

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

drwxrwsr-x 7 ubuntu project01 4096 Jul 24 01:01 /home/ubuntu/project01.git/
[3] Verify to use repository with users who are in the group for share added in [1].
noble@dlp:~$
mkdir work

noble@dlp:~$
cd work
noble@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/noble/work/.git/

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

noble@dlp:~/work$
git config --global user.email "noble@dlp.srv.world"
# create a test file and push it to repository

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

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

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

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

noble@dlp:~/work$
git remote add origin /home/ubuntu/project01.git

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

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 232 bytes | 232.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To /home/ubuntu/project01.git
 * [new branch]      master -> master
Matched Content