gitosis的使用

Setup and use of git repository on Fedora

Please read the full documentation before you try it!

Install Gitosis

  sudo yum install gitosis

Update ssh pub key

If you are an admin, copy your ~/.ssh/id_rsa.pub (or id_dsa.pub) to the remote server system and add it to the repo using:

   sudo -H -u gitosis gitosis-init < /path/to/id_rsa.pub

Test

From your local system, try to get the repo via clone:

  git clone gitosis@server_name:gitosis-admin.git

Add project, user and test

Add the following to gitosis.conf:

  [group hello-project]
  writable = hello_project
  members = shaks@fedora

Commit the same using:

  git commit -a -m "Allow shaks to hello_project repo"

Push to server:

  git push

Create local directory, and push to server

Create local directory:

  mkdir hello_project

Add files:

  cp -r /path/to/files hello_project/*

git-init, add and push:

  git init
  git remote add origin gitosis@server_name:hello_project.git
  git add .
  git commit -m "Comment"
  git push origin master:refs/heads/master

You will get an output like:

  Initialized empty Git repository in ./
  Counting objects: 1734, done.
  Compressing objects: 100% (1703/1703), done.
  Writing objects: 100% (1734/1734), 2.48 MiB | 2061 KiB/s, done.
  Total 1734 (delta 693), reused 0 (delta 0)
  To gitosis@server_name:hello_project.git
   * [new branch]      master -> master

Adding new users

Copy the user.pub file to gitosis-admin/keydir. Update the gitosis.conf, to say:

  members = shyam anita

The corresponding .pub files are shyam.pub, and anita.pub. Commit it.

  git add .
  git commit -m "Added anita to repository"
  git push

Now, the user can clone the repo from his/her system:

  git clone gitosis@server_name:demo.git

The user repo only needs to make changes and push the changes to the server using git push, after committing the same for the master. If you create new branches, you need to tell git about it:

  git push origin branch_name

When you checkout, the branches will be seen in git branch -r output. You can then check them out, if you want using:

  git checkout -tb remote_branch_name origin/remote_branch_name

So, the remote_branch_name will be the same name as origin/remote_branch_name, so git knows where to push back the changes. Make some changes, commits, and push:

  git push origin remote_branch_name

If you don't want to give -t in the command line (you will still need to checkout -b the remote_branch to a local branch with the same name), and you want to keep track for all repositories, do the following:

  git config --global branch.autosetupmerge true

OR

Add the following to your ~/.gitconfig:

[branch]
        autosetupmerge = true

Fetching changes from remote repo

If you already have cloned a git repo and have it locally, you can get updates from remote repo or upstream using:

  git fetch

The remote branch is listed with:

  git branch -r

and it shows:

  origin/master

You can see the changes between the local master and the remote origin/master using:

  git diff master..origin/master

To merge the changes to your local repo, you can use:

  git merge origin/master

So, fetch only downloads the changes, and you can see the changes before doing a merge. git pull will do a fetch and a merge. But, you need to add the following in your project .git/config.

  [branch "master"]
        remote = origin
        merge = refs/heads/master

Or, you can simply do from the current master branch:

  git pull . remotes/origin/master

Deleting a repo

Clone the gitosis-admin.git, remove the entry for the project (the [group project_name]) in gitosis.conf. Commit the same, and push it to the server:

  git add gitosis.conf
  git commit -m "Removed project_name repo"
  git push

Login to the remote server, and remove the directory, /var/lib/gitosis/repositories/project_name.git.

.gitignore

Example: gitignore in top-level sources directory
*.log
*.sqlite3
config/database.yml
config/settings.yml
tmp/**/*

*.o
a.out

*.svn

Project file description hasn't been set

If you get the above error:

$ git push
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 400 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
*** Project description file hasn't been set
error: hooks/update exited with error code 1
error: hook declined to update refs/heads/master
To gitosis@192.168.1.17:gitosis-admin.git
 ! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'gitosis@192.168.1.17:gitosis-admin.git'

Update .git/description on local copy and remote /var/lib/repositories/repository_name.git/description file, and git push.

git-daemon

Install git-daemon on the server:

  sudo yum install git-daemon

You can start it on the server using:

  sudo -u gitosis git-daemon --base-path=/var/lib/gitosis/repositories/ --export-all

Now, anyone can checkout the repository code as read-only:

  git clone git://server_name/hello_project.git

But, if you want to push, you will need to have your SSH keys uploaded to the repo, and you will need to use:

  git clone gitosis@server_name:project.git

git-daemon can be started from xinetd with the following sample /etc/xinetd.d/git:

# default: off
# description: The git dæmon allows git repositories to be exported using
#       the git:// protocol.

service git
{
        disable         = no
        socket_type     = stream
        wait            = no
        user            = gitosis
        server          = /usr/bin/git-daemon
        server_args     = --base-path=/var/lib/gitosis/repositories/ --export-all --syslog --inetd --verbose
        log_on_failure  += USERID
# xinetd doesn't do this by default. bug #195265
        flags           = IPv6
}

Restart xinetd:

  /etc/init.d/xinetd restart

You can check if git-daemon is running from the output of:

  netstat -na | grep :9418
Git是非常著名的分布式版本控制系统。 Gitosis则是方便通过Git与ssh架设中央服务器的软件。这篇文章的安装流程写得很明了,但使用中还是遇到了些许问题,本文算是该流程的补充。如果打算通过Gitosis架设服务器通过本文或许可以少走不少弯路。 一、架设步骤 1. 下载并安装python setuptools sudo apt-get install python-setuptools 2. 下载并安装gitosis cd ~/src git clone git://eagain.net/gitosis.git cd gitosis python setup.py install 3. 添加用户git sudo adduser \ --system \ --shell /bin/sh \ --gecos 'git version control' \ --group \ --disabled-password \ --home /home/git \ git 4. 生成本机密钥 切换到个人机,如果已有~/.ssh/id_rsa.pub略过此步 ssh-keygen -t rsa 5. 上传密钥到服务器临时目录 scp ~/.ssh/id_rsa.pub 用户名@主机:/tmp 6. 初使化gitosis 切回到服务器 sudo -H -u git gitosis-init < /tmp/id_rsa.pub 7. 修改post-update权限 sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update 8. clone gitosis管理平台 git clone git@主机名:gitosis-admin.git cd gitosis-admin 9. 安装完成 通过修改gitosis-admin管理gitosis用户权限 添加公密到keydir,添加用户 修改完后commit,push到中服务器即可完成仓库权限的相关操作。 二、实例 目标:添加用户 john 和仓库 foo 到gitosis,并和管理员miao合作管理 1. 用户john添加并发送id_rsa.pub给miao john:~$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/john/.ssh/id_rsa): Created directory '/home/john/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/john/.ssh/id_rsa. Your public key has been saved in /home/john/.ssh/id_rsa.pub. john:~$ cp /home/john/.ssh/id_rsa.pub /tmp
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值