Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Gitosis installation and configuration of Git server and how to use gitignore

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the "Gitosis installation and configuration of Git server and how to use gitignore". In daily operation, I believe many people have doubts about the installation and configuration of Git server Gitosis and the use of gitignore. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "Gitosis installation and configuration of Git server and how to use gitignore". Next, please follow the editor to study!

Git Server Gitosis installation Settings

1. Install the openssh server

The code is as follows:

Sudo apt-get install openssh-server openssh-client

2. Create personal public and private keys

Under the default user's home directory path, run the following command and follow the prompts to create the public and private keys

The code is as follows:

Ssh-keygen-t rsa

2048 bits are generated by default, and if you need to improve the security level, you can also create public and private keys with the following command

The code is as follows:

Ssh-keygen-t rsa-b 4096

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

The code is as follows:

Id_rsa id_rsa.pub known_hosts

3. Install the git server

The code is as follows:

Sudo apt-get install git-core

4. Configure the git server

Create a git server administrative user

The code is as follows:

Sudo useradd-m git

Sudo passwd git

Create a git warehouse storage directory

The code is as follows:

Sudo mkdir / home/git/repositories

Set git warehouse permissions

The code is as follows:

Sudo chown git:git / home/git/repositories

Sudo chmod 755 / home/git/repositories

Initialize global settings

The code is as follows:

Git config-global user.name "myname"

Git config-global user.email "myname@server"

5. Install setup tool of python

The code is as follows:

Sudo apt-get install python-setuptools

6. Obtain and install gitosis

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

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

The code is as follows:

Cd ~

Git clone git@hostname: user name / gitosis-admin.git

Cd gitosis-admin/

After each user generates their own ssh public key files according to the method mentioned above, the server administrator takes all the ssh public key files and copies them to the keydir directory.

Modify the gitosis.conf file as follows

The code is as follows:

[gitosis]

[group gitosis-admin]

Writable = gitosis-admin

Members = a@server1

[group developers]

Writable = helloworld

Members = a@server1 b@server2

[group test]

Readonly = helloworld

Members = c@server3

This configuration file expresses the following meaning: the member of the gitosis-admin group has a, which has read and write access to the gitosis-admin repository; the developers group has two members, which have read and write access to the helloworld repository; and the test group has a member of c and has read-only access to the helloworld repository. Of course, currently the changes to these configuration files are only local to you, and you have to push them to gitserver to really take effect. Add new files, submit, and push to the git server:

The code is as follows:

Git add.

Git commit-am "add helloworld project and users"

Git remote add origin ssh://git@hostname/helloworld.git

Git push origin master

9. Install apache2

The code is as follows:

Sudo apt-get install apache2

10. Install gitweb

The code is as follows:

Sudo apt-get install gitweb

11. Configure gitweb

There is no css load by default. Connect the static files to be used by gitweb under DocumentRoot:

The code is as follows:

Cd / var/www/

Sudo ln-s / usr/share/gitweb/*.

Modify the configuration:

The code is as follows:

Sudo vi / etc/gitweb.conf

Change $projectroot to the 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 web. Http://localhost/cgi-bin/gitweb.cgi

Modify / etc/gitweb.conf content:

The code is as follows:

# path to git projects (.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/,. When gitweb is installed, the 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 the gitweb.cgi installed in gitweb in / usr/lib/cgi-bin to the original configured cgi-bin path, and add the following at the end of the apache configuration file / etc/apache2/apache.conf:

The code is as follows:

SetEnv GITWEB_CONFIG / etc/gitweb.conf

Options FollowSymlinks ExecCGI

Allow from all

AllowOverride all

Order allow,deny

SetHandler cgi-script

RewriteEngine on

RewriteCond% {REQUEST_FILENAME}!-f

RewriteCond% {REQUEST_FILENAME}!-d

RewriteRule ^. * / gitweb.cgi/$0 [LMIT PT]

Git uses gitignore to establish project filtering rules

In the process of collaborative development code management, we often encounter some temporary files, configuration files, or generated files, these files will be different due to different developers, if you use git add. If all files are included in the git library, frequent changes and push will occur, which will cause inconvenience to development.

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

Two filtering mechanisms are provided in git, one is the global filtering mechanism, which is applicable to all git, and the other is the filtering rules used for an item. Individuals tend to the second kind.

Take one of my projects as an example, this project is developed with. Net,. Config files, including generated bin/Debug, bin/Release files, etc., I hope not to join the git management.

Create a .gitignore file under the code directory: vim .gitignore, which reads as follows:

The code is as follows:

# filter database files, sln solution files, configuration files

* .mdb

* .ldb

* .sln

* .config

# filter folder Debug,Release,obj

Debug/

Release/

Obj/

Then call git add. And execute git commit.

At this point, the study on "Gitosis installation and configuration of Git server and how to use gitignore" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report