`
onedada
  • 浏览: 103385 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
社区版块
存档分类
最新评论

freebsd上安装git(1)

    博客分类:
  • Unix
 
阅读更多

本文转自:     http://forums.freebsd.org/showthread.php?t=10810

 

 

 

How to setup a Git repository


 

This howto will describe how to setup a Git repository:
  • Dedicated user for Git repos
  • SSH will be used for commits
  • Enable gitweb for web access (Apache will be used)
  • Anonymous cloning using the Git protocol

For those who don't know what Git is:
You should know how to use Git before reading on.

Install devel/git. Select GITWEB. SVN, P4, and CVS are optional. Deselect them if you don't plan to use them.

Create a git user with uid and gid as 9418:
Code:
# pw groupadd -n git -g 9418
# pw useradd -n git -u 9418 -g git -c git -d /git \
	-s /usr/local/libexec/git-core/git-shell -h -
The git-shell is used for this user, and home is set as /git/. The repos will be under /git/base/.

Make sure the permissions of the directory are correct and create /git/base/:
Code:
# chown git:git /git/
# chmod 755 /git
# mkdir /git/base/
# chown git:git /git/base/
# chmod 775 /git/base/
Next, add users to the git group to be able to create repositories under /git/base/. This isn't necessary for users who only need commit access.
Code:
# vi /etc/group
...
git:*:9418:user1,user2
We'll be using SSH keys for authenication, so collect the public keys of all the users who need commit access. Then, put the public keys into the right place:
Code:
# mkdir /git/.ssh/
# chmod 700 /git/.ssh/
# touch /git/.ssh/authorized_keys
# chmod 600 /git/.ssh/authorized_keys
(Put the public keys into authorized_keys, one per line)
# chown -R git:git /git/.ssh/
Everything should be set now. Let's create a repo for testing (change to a user that has been added to the git group and has commit access).
Code:
$ mkdir /git/base/test.git
$ cd /git/base/test.git && git init --bare --shared
Create a local repo and commit:
Code:
$ mkdir ~/test
$ cd ~/test && git init
$ echo '123456' > foo
$ git add .
$ git commit
Now push it into the remote repo (remember to replace git.example.com with your own hostname):
Code:
$ git remote add origin git@git.example.com:base/test.git
$ git push origin master
Don't delete the test repo yet.

Since the git repo should be up and working by now, let's enable gitweb for web access. Apache's VirtualHost will be used for this.

Copy gitweb files to /home/www/git/:
Code:
$ cp /usr/local/share/examples/git/gitweb/git* /home/www/git/
Modify Apache settings (change the ServerName and the access and error log paths as necessary):
Code:
<VirtualHost *:80>
  ServerAdmin webmaster@yourhostname
  DocumentRoot "/home/www/git"
  ServerName git.example.com
  ErrorLog "/path/to/errolog"
  CustomLog "/path/to/accesslog" combined

  <Directory "/home/www/git">
    Options ExecCGI
    Order allow,deny
    Allow from all

    DirectoryIndex gitweb.cgi
    AddHandler cgi-script .cgi
  </Directory>
</VirtualHost>
Now edit gitweb.cgi:
Code:
-our $projectroot = "/pub/scm";
+our $projectroot = "/git/base";
...
-our $home_link_str = "projects";
+our $home_link_str = "base";
...
-our $site_name = ""
+our $site_name = "git.example.com"
...
-our $home_text = "indextext.html";
+our $home_text = "content.html"; (Leave empty if unnecessary)
...
-our $projects_list_description_width = 25;
+our $projects_list_description_width = 40; (Give the description a bit more space)
Change the $site_header, $home_text, and $site_footer as needed.

Open up your browser and check if it's working.

You might notice that the description of the test repo hasn't been modified yet. You might also want to change the owner.

For the description, edit /git/base/test.git/description. Put this into /git/base/test.git/config to change the owner:
Code:
[gitweb]
        owner = Your Name
Only the Git protocol isn't working now.

Add this to /etc/rc.conf:
Code:
git_daemon_enable="YES"
git_daemon_directory="/git"
git_daemon_flags="--syslog --base-path=/git --export-all"
Start the daemon:
Code:
# /usr/local/etc/rc.d/git_daemon start
You should now be able to clone using the Git protocol. Try it out:
Code:
$ cd /tmp/
$ git clone git://git.example.com/base/test.git
One last thing. You might want to list URLs for cloning repos on the summary page of test.git in gitweb. Just add this line (the url line) to the [gitweb] section of /git/base/test.git/config:
Code:
[gitweb]
        owner = Your Name
        url = git://git.example.com/base/test.git
This line can appear more than once if there are multiple URLs:
Code:
[gitweb]
        owner = Your Name
        url = git://git.example.com/base/test.git
        url = git@git.example.com:base/test.git

 


Last edited by dennylin93; February 4th, 2010 at 02:30.

 

Reply With Quote

 

The Following 13 Users Say Thank You to dennylin93 For This Useful Post:
beginner (January 30th, 2010), blodan (July 8th, 2012), draco003 (September 26th, 2011), fefo (January 31st, 2010), graudeejs (January 30th, 2010), jkusniar (February 2nd, 2010), lme@ (November 11th, 2012), marino (August 15th, 2010), Symbiosis (June 8th, 2010), unconnected (September 23rd, 2010), UNIXgod (October 21st, 2010), vertexSymphony (October 25th, 2010), VictorGT (October 21st, 2010)

 

  #2  
Old October 21st, 2010, 15:53
Junior Member
 
Join Date: Oct 2010
Posts: 1
Thanks: 1
Thanked 1 Time in 1 Post
 
Default

Thanks a lot for this useful article!

I've noticed one problem on my FreeBSD 7.2 - looks like it is better to add one more flag (--detach) to the rc.conf:
Code:
git_daemon_flags="--syslog --base-path=/git --export-all --detach"

Last edited by DutchDaemon; October 21st, 2010 at 18:32.
Reply With Quote
The Following User Says Thank You to VictorGT For This Useful Post:
blodan (July 8th, 2012)

 

  #3  
Old October 21st, 2010, 16:35
graudeejs's Avatar
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,488
Thanks: 417
Thanked 594 Times in 465 Posts
 
Default

You can use devel/py-gitosis to manage git users.
This way system only needs 1 git user. Other users will be virtual users (authorization with ssh public/private keys)

It is very nice peace of software...
I use gitosis & cgit at git.bsdroot.lv
Reply With Quote
The Following User Says Thank You to graudeejs For This Useful Post:
draco003 (September 26th, 2011)

 

  #4  
Old May 25th, 2012, 20:05
Junior Member
 
Join Date: May 2012
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
 
Default

Quote:
Originally Posted by VictorGT View Post
Thanks a lot for this useful article!

I've noticed one problem on my FreeBSD 7.2 - looks like it is better to add one more flag (--detach) to the rc.conf:
Code:
git_daemon_flags="--syslog --base-path=/git --export-all --detach"
I have the same problem on FreeBSD 9, if you don't add --detach in rc.conf, the daemon is started in the foreground and the boot process is stuck at launching the daemon (before SSH :/)

Except that, everything works very well ! Thank you.

Last edited by DutchDaemon; May 25th, 2012 at 20:43. Reason: Proper formatting / spelling
Reply With Quote
The Following User Says Thank You to blaize For This Useful Post:
blodan (July 8th, 2012)

 

Reply

 

 

 

 

 

分享到:
评论

相关推荐

    FreeBSD11.0下Git服务器搭建

    freeBSD11.0系列安装文档,本人实际操作记录,希望给大家带来上些帮助

    FreeBSD11下安装MySQL数据库

    以下是在FreeBSD 11上安装MySQL数据库的详细步骤: **一、更新系统** 在开始安装任何新软件之前,首先要确保你的FreeBSD系统是最新的。通过运行`freebsd-update fetch install`命令来获取最新的安全补丁和更新。 ...

    用于对大型文件进行版本控制的 Git 扩展.zip

    二进制包包含一个脚本,它将在系统上安装 Git LFS 二进制文件$PATH。特别是在 Windows 上,您可能需要重新启动命令 shell,以便任何更改$PATH生效,并且 Git 可以找到 Git LFS 二进制文件。运行git lfs install以...

    freeBSD架设管理与应用

    1. 安装流程:FreeBSD提供了多种安装方式,包括光盘、USB设备、网络安装等。用户可以根据自己的硬件环境选择最适合的安装方法。 2. 分区规划:合理规划硬盘分区对于系统的高效运行至关重要,包括根分区、用户数据...

    freebsd开发环境解决方案

    1. **稳定性**:FreeBSD非常稳定,这使得开发者可以在一个可靠的平台上进行开发工作。 2. **安全性**:FreeBSD内置了多种安全机制,能够有效保护系统的安全。 3. **性能优化**:针对特定硬件平台进行了优化,能够...

    FreeBSD文档手册

    - 源代码管理:git、svn版本控制系统在FreeBSD上的使用。 9. **虚拟化与容器技术** - jails:FreeBSD的轻量级容器技术,提供资源隔离和安全控制。 - bhyve:FreeBSD的Hypervisor,支持虚拟机。 10. **高级主题*...

    FreeBSD使用大全.第2版

    13. **FreeBSD下的开发环境**:介绍在FreeBSD上建立C/C++、Python、Perl等开发环境,以及版本控制工具如Git的使用。 14. **故障排查**:分享诊断和解决系统问题的技巧,如日志分析、调试工具的使用以及性能监视工具...

    FreeBSD系统编程 中文版

    综上所述,FreeBSD系统编程涉及多个层次的技术和概念,从底层硬件到高层应用,从单机到网络,都需要系统地学习和实践。通过阅读《FreeBSD系统编程》这样的资源,开发者可以逐步掌握这一领域的核心技能。

    freebsd 内核编译

    FreeBSD的源代码可以通过ports或git获取。通常,使用`fetch`命令从官方服务器下载最新的源代码: ``` cd /usr/src fetch -o - https://raw.githubusercontent.com/freebsd/freebsd/master/FETCHINFO | sh ``` 这将...

    freeBSD_Porter中文手册

    **FreeBSD Porter中文手册**是针对FreeBSD操作系统中Porter这一角色的专业指南,旨在帮助开发者和系统管理员理解和掌握如何在FreeBSD系统上构建、维护和管理ports。这本手册是官方发布的,共有100多页,以中文形式...

    freeBSD中文使用手册

    2. **Perl/Python/Ruby等语言**:在FreeBSD上安装和使用这些脚本语言。 3. **版本控制系统**:如Git的安装和使用,进行代码管理。 4. **构建C/C++项目**:讲解Makefile的编写和项目构建过程。 **八、故障排查和...

    freebsd_valgrind:向Valgrind的FreeBSD端口上游的又一次尝试

    使代码处于足够好的状态,以便将其集成到源软件上的主要Valgrind存储库中(git://sourceware.org/git/valgrind.git) 替换当前的Valgrind FreeBSD端口版本。 当前版本为3.10,带有一些向后移植的修补程序。 我不...

    如何定制自己的压缩的FreeBSD内核

    1. **获取源代码**:FreeBSD的源代码可以从官方Git仓库或者ISO镜像的`/usr/src`目录中获取。你可以使用`git clone`命令或直接从DVD或USB驱动器上提取。 2. **配置内核**:进入`/usr/src/sys/`目录,然后选择对应...

    freebsd命令行提示符的修改

    例如,可以加入时间戳、Git分支名称等信息,使命令行提示符包含更多有用的信息。 通过上述步骤,用户可以根据自己的需求对FreeBSD系统的命令行提示符进行个性化设置,从而提升日常工作的效率和体验。

    freebsd-jenkins-tutorial:在 FreeBSD 上设置 Jenkins CI 服务器的教程

    关于本教程解释了如何在 FreeBSD 上安装以及 PHP、Node.js、git 和几个任务运行器。介绍如果您使用 PHP(PHP 超文本预处理器)开发应用程序,您可能已经阅读或听说现在许多项目选择敏捷方法来快速进行。 这包括测试...

    kubectl-freebsd:如何在FreeBSD上构建和运行kubectl

    kubectl-freebsd-如何在FreeBSD上构建和运行kubectl TLDR-简单方法 $ fetch https://github.com/dcasati/kubectl-freebsd/releases/download/release-1.9/kubectl $ chmod +x kubectl $ sudo mv kubectl /usr/local/...

    git-lfs:Git扩展,用于对大文件进行版本控制

    您可以通过几种不同的方式来安装Git LFS客户端,具体取决于您的设置和首选项。 Linux用户。 可从获得Debian和RPM软件包。 macOS用户。 瓶已分发,可以通过brew install git-lfs 。 Windows用户。 Git LFS包含在的...

    FreeBSD13-zsh.ova.rar

    **使用ZSH在FreeBSD 13上的实践** 安装完ZSH后,用户可能想要配置一个适合自己的环境。这通常涉及编辑`.zshrc`文件,设置个性化提示符,启用或禁用特定的插件,以及调整其他各种设置。例如,安装Oh My ZSH并启用...

    git-info-bar:Git shell 插件提供了一个高度明确的 git 信息视图-开源

    关键词:gitbash git-bash git bash bashgit bash-git bash git gitksh git-ksh git ksh kshgit ksh-git ksh git shell 插件git shell 集成; Linux FreeBSD Windows 最后更改:2013-12-10 - v1.2.0 - 错误修复。 ...

Global site tag (gtag.js) - Google Analytics