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 [email protected]:gitosis-admin.git
 ! [remote rejected] master -> master (hook declined)
error: failed to push some refs to '[email protected]: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)