Gitsis installation and configuration of GIT server and how to use gitignore

Time:2021-5-30

Git server gitosis setup

1. Install openssh server

Copy code

The code is as follows:

sudo apt-get install openssh-server openssh-client

2. Create personal public and private keys

In the default user’s home directory path, run the following command to create the public key and private key

Copy code

The code is as follows:

ssh-keygen -t rsa

2048 bits are generated by default. If you need to improve the security level, you can also create the public key and private key through the following command

Copy code

The code is as follows:

ssh-keygen -t rsa -b 4096

By default, the public key and private key are saved in ~ /. SSH directory, as follows:

Copy code

The code is as follows:

id_rsa id_rsa.pub known_hosts

3. Install git server

Copy code

The code is as follows:

sudo apt-get install git-core

4. Configure git server

Create git server to manage users

Copy code

The code is as follows:

sudo useradd -m git
sudo passwd git

Create git warehouse storage directory

Copy code

The code is as follows:

sudo mkdir /home/git/repositories

Setting git warehouse permissions

Copy code

The code is as follows:

sudo chown git:git /home/git/repositories
sudo chmod 755 /home/git/repositories

Initialize global settings

Copy code

The code is as follows:

git config –global user.name “myname”
git config –global user.email “[email protected]

5. Install the setup tool of Python

Copy code

The code is as follows:

sudo apt-get install python-setuptools

6. Get and install gitosis

Copy code

The code is as follows:

cd /tmp
git clone https://github.com/res0nat0r/gitosis.git
cd gitosis
sudo python setup.py install

7. Configure gitosis

Copy code

The code is as follows:

cp ~/.ssh/id_rsa.pub /tmp
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

8. Manage gitosis configuration

Copy code

The code is as follows:

cd ~
git clone [email protected] : user name / gitosis-admin.git
cd gitosis-admin/

After each user generates their own SSH public key file according to the method mentioned above, the server administrator takes everyone’s SSH public key file and copies it to the keydir directory.

Modify the gitosis. Conf file as follows

Copy code

The code is as follows:

[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = [email protected]
[group developers]
writable = helloworld
members = [email protected] [email protected]
[group test]
readonly = helloworld
members = [email protected]

This configuration file expresses the following meanings: A is a member of the gitosis Admin Group, which has read and write access to the gitosis admin repository; Developers group has two members, a and B. this group has read and write access to HelloWorld warehouse; The test group has a member of C and has read-only access to the HelloWorld repository. Of course, at present, the modification of these configuration files is only in your local area, and you must push them to git server to take effect. Add new file, submit and push to git server:

Copy code

The code is as follows:

git add .
git commit -am “add helloworld project and users”
git remote add origin ssh://[email protected]/helloworld.git
git push origin master

9. Install apache2

Copy code

The code is as follows:

sudo apt-get install apache2

10. Install gitweb

Copy code

The code is as follows:

sudo apt-get install gitweb

11. Configure gitweb

There is no CSS loading by default. Connect the static file to be used in gitweb to DocumentRoot

Copy code

The code is as follows:

cd /var/www/
sudo ln -s /usr/share/gitweb/* .

Modify configuration:

Copy code

The code is as follows:

sudo vi /etc/gitweb.conf

Change $projectroot to git repository directory (for example, / home / git / repositories), and refresh the browser after saving.

If the project is not found, you need to change the property of $projectroot / *. Git to 755, so that Apache users can read it. You can just change the GIT that you need to let others access through the web. http://localhost/cgi-bin/gitweb.cgi

Modify the content of / etc / gitweb.conf:

Copy code

The code is as follows:

# path to git projects (<project>.git)
#$projectroot = “/var/cache/git”;
$projectroot = “/home/git/repositories”;
# directory to use for temp files
$git_temp = “/tmp”;
# target of the home link on top of all pages
$home_link = $my_uri || “/”;
# html text to include at home page
$home_text = “indextext.html”;
# file with project list; by default, simply scan the projectroot dir.
$projects_list = $projectroot;
# stylesheet to use
@stylesheets = (“/gitweb/static/gitweb.css”);
# javascript code for gitweb
$javascript = “gitweb/static/gitweb.js”;
# logo to use
$logo = “/gitweb/static/git-logo.png”;
# the ‘favicon’
$favicon = “/gitweb/static/git-favicon.png”;
# git-diff-tree(1) options to use for generated patches
#@diff_opts = (“-M”);
@diff_opts = ();

12. Configure apache2

The default web directory in Ubuntu is / var / www, and the default CGI directory is / usr / lib / CGI bin /. After gitweb is installed, gitweb.cgi of gitweb will be automatically placed in this directory.

If your CGI path is not the default / usr / lib / CGI bin /, you need to copy gitweb.cgi installed in / usr / lib / CGI bin to the original CGI bin path, and add the following at the end of / etc / apache2 / apache.conf, the configuration file of Apache

Copy code

The code is as follows:

SetEnv GITWEB_CONFIG /etc/gitweb.conf
<Directory “/srv/www/cgi-bin/gitweb”>
Options FollowSymlinks ExecCGI
Allow from all
AllowOverride all
Order allow,deny
<Files gitweb.cgi>
SetHandler cgi-script
</Files>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
</Directory>

Git uses gitignore to create project filtering rules
In the process of collaborative development code management, we often encounter some temporary files, configuration files, or generated files. These files are different due to different development ends. If we use git add. To put all files into git library, there will be frequent changes and push, which will cause inconvenience in development.

Git can easily help us solve this problem, that is to establish project file filtering rules.

Git provides two filtering mechanisms. One is global filtering mechanism, which is applicable to all GITS; The other is the filtering rules used for a project. Individuals tend to the second.

Take one of my projects as an example. The project is developed with. Net,. Config file, including generated bin / debug, bin / release file, etc. I hope not to join git management.

Create a. Gitignore file in the code directory: vim. Gitignore. The content is as follows:

Copy code

The code is as follows:

#Filter database files, SLN solution files and configuration files
*.mdb
*.ldb
*.sln
*.config

#Filter folder debug, release, obj
Debug/
Release/
obj/

Then call git add. and execute git commit.