Jump to content

Git repository on this server: Difference between revisions

From HW wiki
No edit summary
Line 1: Line 1:
== Repository Types ==
== Repository Types ==  
 
This server can host two types of Git repositories.
This server can host two types of Git repositories.
;Central repositories: These repositories are managed by [http://github.com/sitaramc/gitolite Gitolite tool], which allows to conveniently manage repository permissions. Repositories, which are world readable can be [http://rtime.felk.cvut.cz/gitweb browsed online].
;Central repositories: These repositories are managed by [http://github.com/sitaramc/gitolite Gitolite tool], which allows to conveniently manage repository permissions. World readable repositories can be [http://rtime.felk.cvut.cz/gitweb browsed online].
;Personal repositories: Any user with shell access to this server can create his/her own git repository under his/her home directory and make it public using git protocol.
;Personal repositories: Any user with shell access to this server can create his/her own git repository under his/her home directory and make it public using git protocol.


Line 12: Line 13:
It is stored by default at <tt>~/.ssh/id_rsa.pub</tt>.
It is stored by default at <tt>~/.ssh/id_rsa.pub</tt>.


During the key creation you will be asked for a passphrase. If you do not specify any passphrase, anybody with access to your <tt>~/.ssh</tt> directory could access your repositories. If you specify the key, the passphrase will need to be entered whenever to use the key. By using <tt>ssh-add</tt> command you can specify the passphrase only once and the decrypted key will be remebered in the memory.
During the key creation you will be asked for a passphrase. If you do not specify any passphrase, anybody with access to your <tt>~/.ssh</tt> directory could access your repositories. If you specify the key, the passphrase will need to be entered whenever to use the key. By using <tt>ssh-add</tt> command you can specify the passphrase only once and the decrypted key will be remembered in the memory.


=== Creating central repositories ===
=== Creating central repositories ===


To create the repository send an email to the [http://rtime.felk.cvut.cz/~sojka/ administrator] with the name of the repository, a short description and a list of people (SSH public keys) who should have access to the repository.
To create a repository send an email to the [http://rtime.felk.cvut.cz/~sojka/ administrator] with the name of the repository, a short description and a list of people (SSH public keys) who should have access to the repository.


=== Automatic creation of repositories ===
=== Automatic creation of repositories ===


Our group staff members can create their repositories without asking the administrator. It is simply a matter of pushing the repository to a special URL containing the login like this:
Our group staff members can create their repositories without asking the administrator. It is simply a matter of pushing the repository to a special URL containing the login, like this:


  git push ssh://git@rtime.felk.cvut.cz/«login»/«whatever» HEAD
  git push --set-upstream ssh://git@rtime.felk.cvut.cz/«login»/«whatever» HEAD


This will create a new repository called «whatever» (it it does not exist yet) and push the current HEAD to it. If you want to make this repository default for pushing and pulling (i.e. you can type <tt>git push/pull</tt> without parameters), you can run instead:
This will create a new repository called «whatever» (if it does not exist yet) and push the current HEAD to it. It also makes this repository the default for pushing and pulling (this is what --set-upstream does).
 
git push --set-upstream ssh://git@rtime.felk.cvut.cz/«login»/«whatever» HEAD


==== Gitweb description for automatic repositories ====
==== Gitweb description for automatic repositories ====
Line 43: Line 42:
where filter is optional string used to filter the list.
where filter is optional string used to filter the list.


It there are wildcard (automatic) repositories, as in the example
It there are wildcard (automatic) repositories, as in the example below, you will only see the wildcard pattern and not the created repositories.
below, you will only see the wildcard pattern and not the created
repositories.


   C  R  W      fpga/[a-zA-Z0-9].*
   C  R  W      fpga/[a-zA-Z0-9].*


To expand the wildcards, use the command <tt>expand</tt> instead of
To expand the wildcards, use the command <tt>expand</tt> instead of info. This command is a way slower than info command!
info. This command is a way slower than info command!


  ssh git@rtime.felk.cvut.cz expand
  ssh git@rtime.felk.cvut.cz expand
Line 57: Line 53:
==== Permissions to automatic repositories ====
==== Permissions to automatic repositories ====


The owners of automatically created repositories can manage the
The owners of automatically created repositories can manage the access permissions by themselves:
access permissions by themselves:
  cat > perms
  cat > perms
  READERS pepa franta
  READERS pepa franta
Line 72: Line 67:
More information can be found in [https://github.com/sitaramc/gitolite/blob/master/doc/wildcard-repositories.mkd#_handing_out_rights_to_wildcard_matched_repos Gitolite manual].
More information can be found in [https://github.com/sitaramc/gitolite/blob/master/doc/wildcard-repositories.mkd#_handing_out_rights_to_wildcard_matched_repos Gitolite manual].


To allow public access and listing on [http://rtime.felk.cvut.cz/gitweb/ gitweb]
To allow public access and listing on [http://rtime.felk.cvut.cz/gitweb/ gitweb] page use the following command sequence:
page use the following command sequence:


   ssh git@rtime.felk.cvut.cz getperms ''repo-name'' > perms
   ssh git@rtime.felk.cvut.cz getperms ''repo-name'' > perms
Line 81: Line 75:
[http://rtime/gitweb/sojka/gl-perm.git/blob/refs/heads/master:/gl-perm This script] can be used to make permission management easier.
[http://rtime/gitweb/sojka/gl-perm.git/blob/refs/heads/master:/gl-perm This script] can be used to make permission management easier.


== Personal repositories ==
=== Accessing the repository ===


A personal repository can be created this way:
After [[Git#Install_Git|installing Git]] on your local computer, you
can access the repository as follows.


ssh ''login''@rtime.felk.cvut.cz
==== Cloning the repository ====
mkdir $HOME/''myproject''.git
cd $HOME/''myproject''.git
git init --bare --shared=everybody


If you want to make your repository public, it has to be accessible by user <tt>gitdaemon</tt>. It is usually sufficient to give "x" permission to your home directory:
Read/Write access (for users with registered SSH key):
  setfacl -m user:gitdaemon:x $HOME
  git clone ssh://git@rtime.felk.cvut.cz/''repo-name''
 
== Accessing the repository ==


Everybody can use one of following commands to work with the code in the repository (it is not necessary add origin and configure remote branches as described above):
Read-only access (for public repositories only):
==== Central repository ====
Read-only access for public repositories:
  git clone git://rtime.felk.cvut.cz/''repo-name''.git
  git clone git://rtime.felk.cvut.cz/''repo-name''.git


Access managed by gitolite (for users with registered SSH key):
==== First push ====
git clone ssh://git@rtime.felk.cvut.cz/''repo-name''
 
==== Personal repository ====
Read-only access for public repositories:
git clone git://rtime.felk.cvut.cz/~''yourlogin/''repo-name''.git
 
=== First push ===
 
After an empty repository is created either by you (personal) of by an admin (central), you can push (upload) the data to it:


* (Optional -- needed only for personal repos): Setup [[Passwordless_SSH|passwordless login to the server]]
After an empty repository is created either by admin (central) or by you (wildcard), you can push (upload) the data to it:
* [[Git#Install_Git|Install Git]] on your local computer


==== For git 1.6.2 and newer ====
===== For git 1.6.2 and newer =====
* [[#Accessing_the_repository|Clone]] the empty repository.
* [[#Cloning the repository|Clone]] the empty repository.
* Put your sources into your cloned repository
* Put your sources into your cloned repository
  git add .            # tells git to track all files in your project
  git add .            # tells git to track all files in your project
Line 122: Line 100:
  git push
  git push


==== For older git versions ====
===== For older git versions =====
* Put your sources into your local repository
* Put your sources into your local repository
  cd your/project
  cd your/project
Line 135: Line 113:
  git push --all
  git push --all


=== Pushing to non-master branches ===
==== Pushing to non-master branches ====


If you are not allowed to push to the master branch but a different one, you have to push like this:
If you are not allowed to push to the master branch but to a different one, you have to push like this:
  git push origin master:your-branch
  git push origin master:your-branch
which pushes our local master branch to the remote your-branch
which pushes your local master branch to the remote your-branch


To make this behavior default run
To make this behavior default run
Line 146: Line 124:
And from now on, it is sufficient to run only
And from now on, it is sufficient to run only
  git push
  git push
== Personal repositories ==
A personal repository can be created this way:
ssh ''login''@rtime.felk.cvut.cz
mkdir $HOME/''myproject''.git
cd $HOME/''myproject''.git
git init --bare --shared=everybody
If you want to make your repository public, it has to be accessible by user <tt>gitdaemon</tt>. It is usually sufficient to give "x" permission to your home directory:
setfacl -m user:gitdaemon:x $HOME
Read-only access for public repositories is possible with the following command:
git clone git://rtime.felk.cvut.cz/~''yourlogin/''repo-name''.git


== Contributing to other projects ==
== Contributing to other projects ==
Line 159: Line 153:
# Push your changes to your personal repository <pre>git push personal</pre>
# Push your changes to your personal repository <pre>git push personal</pre>
# Write email to somebody with write access to merge changes in <tt>git://rtime.felk.cvut.cz/~''yourlogin''/''myproject''.git</tt>
# Write email to somebody with write access to merge changes in <tt>git://rtime.felk.cvut.cz/~''yourlogin''/''myproject''.git</tt>
== Merging changes from forks ==
git remote add fixes git://rtime.felk.cvut.cz/project/forkname.git
git fetch fixes (or git remote update)
git merge fixes/master


== Links to git related documents ==
== Links to git related documents ==

Revision as of 11:25, 15 June 2012

Repository Types

This server can host two types of Git repositories.

Central repositories
These repositories are managed by Gitolite tool, which allows to conveniently manage repository permissions. World readable repositories can be browsed online.
Personal repositories
Any user with shell access to this server can create his/her own git repository under his/her home directory and make it public using git protocol.

Central Repositories

Write access to central repositories can only be given to users who sent their Open SSH public key to the administrator together with their university assigned login name (if any). The SSH key can be created in Linux/Unix (or in MSysGit shell in Windows) by:

 ssh-keygen

It is stored by default at ~/.ssh/id_rsa.pub.

During the key creation you will be asked for a passphrase. If you do not specify any passphrase, anybody with access to your ~/.ssh directory could access your repositories. If you specify the key, the passphrase will need to be entered whenever to use the key. By using ssh-add command you can specify the passphrase only once and the decrypted key will be remembered in the memory.

Creating central repositories

To create a repository send an email to the administrator with the name of the repository, a short description and a list of people (SSH public keys) who should have access to the repository.

Automatic creation of repositories

Our group staff members can create their repositories without asking the administrator. It is simply a matter of pushing the repository to a special URL containing the login, like this:

git push --set-upstream ssh://git@rtime.felk.cvut.cz/«login»/«whatever» HEAD

This will create a new repository called «whatever» (if it does not exist yet) and push the current HEAD to it. It also makes this repository the default for pushing and pulling (this is what --set-upstream does).

Gitweb description for automatic repositories

Similar to the getperms/setperms commands, there are the getdesc/setdesc commands. I.e. you can set the description by:

echo "Description" | ssh git@rtime.felk.cvut.cz setdesc <repo>

Managing central repositories

Finding available repositories

You can find the list of repositories you have access to by running:

ssh git@rtime.felk.cvut.cz info [filter]

where filter is optional string used to filter the list.

It there are wildcard (automatic) repositories, as in the example below, you will only see the wildcard pattern and not the created repositories.

 C  R   W      fpga/[a-zA-Z0-9].*

To expand the wildcards, use the command expand instead of info. This command is a way slower than info command!

ssh git@rtime.felk.cvut.cz expand
ssh git@rtime.felk.cvut.cz expand fpga

Permissions to automatic repositories

The owners of automatically created repositories can manage the access permissions by themselves:

cat > perms
READERS pepa franta
WRITERS kerel lojza
(hit ctrl-d here)

ssh git@rtime.felk.cvut.cz setperms «login»/«whatever» < myperms

The current permissions can be viewed by

ssh git@rtime.felk.cvut.cz getperms «login»/«whatever»

More information can be found in Gitolite manual.

To allow public access and listing on gitweb page use the following command sequence:

 ssh git@rtime.felk.cvut.cz getperms repo-name > perms
 echo "READERS @all" >> perms
 ssh git@rtime.felk.cvut.cz setperms repo-name < perms

This script can be used to make permission management easier.

Accessing the repository

After installing Git on your local computer, you can access the repository as follows.

Cloning the repository

Read/Write access (for users with registered SSH key):

git clone ssh://git@rtime.felk.cvut.cz/repo-name

Read-only access (for public repositories only):

git clone git://rtime.felk.cvut.cz/repo-name.git

First push

After an empty repository is created either by admin (central) or by you (wildcard), you can push (upload) the data to it:

For git 1.6.2 and newer
  • Clone the empty repository.
  • Put your sources into your cloned repository
git add .             # tells git to track all files in your project
git commit            # commits the added files to the repository
  • Push your sources to the server
git push
For older git versions
  • Put your sources into your local repository
cd your/project
git init              # initializes git repository in your project's directory
git add .             # tells git to track all files in your project
git commit            # commits the added files to the repository
  • Then "connect" your repository to the one on this server (replace login by your login and repo-name by the name of repository created for you)
git remote add origin git@rtime.felk.cvut.cz:repo-name  # this is for central repos
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
  1. Push your sources to the server
git push --all

Pushing to non-master branches

If you are not allowed to push to the master branch but to a different one, you have to push like this:

git push origin master:your-branch

which pushes your local master branch to the remote your-branch

To make this behavior default run

git config remote.origin.push master:your-branch

And from now on, it is sufficient to run only

git push


Personal repositories

A personal repository can be created this way:

ssh login@rtime.felk.cvut.cz
mkdir $HOME/myproject.git
cd $HOME/myproject.git
git init --bare --shared=everybody

If you want to make your repository public, it has to be accessible by user gitdaemon. It is usually sufficient to give "x" permission to your home directory:

setfacl -m user:gitdaemon:x $HOME

Read-only access for public repositories is possible with the following command:

git clone git://rtime.felk.cvut.cz/~yourlogin/repo-name.git

Contributing to other projects

Using personal repository to contribute to other projects

If you do not have write access to the repository of some project (not necessarily a central repository on this server), you can work in your personal repository then ask somebody with write access to merge your changes.

  1. Clone a central repository
    git clone git://rtime.felk.cvut.cz/project.git
  2. Add your rtime personal repository as remote (using SSH access)
    git remote add personal yourlogin@rtime.felk.cvut.cz:myproject.git
  3. Edit files in project...
  4. Commit your changes
    git commit ...
  5. Push your changes to your personal repository
    git push personal
  6. Write email to somebody with write access to merge changes in git://rtime.felk.cvut.cz/~yourlogin/myproject.git

Links to git related documents