git: Create a central warehouse in Linux (or bare warehouse: bare repository)

Table of contents

1 Introduction

2. Create steps

step1: cd to the place where you want to put the git-repo

step2: create git repository

3. git clone

4. Set permissions


1 Introduction

        Briefly introduce the steps and some related settings of creating a git repository for multi-person collaborative work in the Linux system. Here it is only considered that users in the same linux server want to access the git-repo, and the settings for accessing the git-repo from the external network are not involved.

        First, assume you have administrator privileges, and assume that you have created a group grp_git to allow members of this group to access the shared git repository.

2. Create steps

step1: cd to the place where you want to put the git-repo

>> cd /path/to/where-you-want-to-put-the-git-repo        

step2: create git repository

>> git init --bare  myrepo.git

        The warehouse initialized with the --bare parameter is generally called a bare warehouse, because the warehouse created in this way does not contain a workspace, that is to say, we cannot execute the Git commands we generally use in this directory.

        After this command is executed, a folder named repo will be created locally, which contains the basic directory of Git. We usually name this folder in the form of adding .git, such as repo.git (this is why we When the warehouse is cloned from GitHub, the address is in the form of xxx.git).

3. git clone

        After the above is created, the user can use the git clone command to clone the warehouse to the local job directory. As follows:

>> git clone /path/to/myrepo.git

        However, users should not be able to push yet. Common git push errors are as follows:

error: insufficient permission for adding an object to repository database ./objects
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit

        The solution is shown in the next chapter.

4. Set permissions

>> cd /path/to/myrepo.git

>> chgrp -R grp_git objects

>> chmod -R g+rws objects

        The chgrp command grants access to members of the grp_git group.

        The “s” option in the “g+rws” is to set the setuid bit on the objects folder. This will make sure any new directory created under objects folder will make the group name from the objects folder which is owned by git group.

        "chmod -R 777 objects" is deprecated.

        In addition to the above settings, you also need to set the git-repo as a shared repository, as follows:

>> git config core.sharedRepository group

        Note that in the above command, "group" is the parameter name, not the group name, that is (in this example) it does not need to be changed to grp_git!

        After executing the above command, you can view the information of the git warehouse by executing the git config command:

$ git config -l
user.name=***
user.email=***
core.repositoryformatversion=0
core.filemode=true
core.bare=true
core.logallrefupdates=true
core.sharedrepository=group

        Well, you're done here, and the git warehouse can be officially put into use as a shared warehouse for multi-person collaborative work.

参考:How to Fix Git Push Insufficient Permission Error for Objects Permanently 

Guess you like

Origin blog.csdn.net/chenxy_bwave/article/details/130197891