Jump to content

Git repository on this server: Difference between revisions

From HW wiki
 
(69 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This server can host two types of Git repositories.
Repositories on rtime server 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].
;Central repositories: These repositories are located under <tt>/var/git</tt> directory and can be [http://rtime.felk.cvut.cz/gitweb browsed online]. This repository can be either created by server administrators or any user can [[#Forking projects hosted on this server|fork an existing repository]]. Central repositories are usually public (read-only accessible to everybody).
;Personal repositories: Any user with shell access can can create his/her own git repository under his/her home directory and make it public using git protocol.


== Creating a personal repository ==
In addition to gitolite repositories, users with shell account can create [[Git repositories in home directories|Git repositories in their home directory]]. This does not require any coordination with the administrator.


ssh ''login''@rtime.felk.cvut.cz
== Getting write access to repositories ==
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>nobody</tt>. It is usually sufficient to give "x" permission to your home directory:
Write access to the repositories can only be given to users who send the following information to the [http://rtime.felk.cvut.cz/~sojka/ administrator]:
setfacl -m user:nobody:x $HOME


== First push ==
# OpenSSH public key
# Login name (for ČVUT people) or email address (for others).


After an empty repository is created either by you (personal) of by an admin (central), you can push (upload) data to it:
=== SSH key creation ===


* Optional: Setup [[Passwordless_SSH|passwordless login to the server]]
The SSH key can be created with one of the following ways. Note that under Windows, methods 1 and 2 only work if [[Media:git-plink.jpg|OpenSSH]] has been selected during Git installation.
* Optional for central repositories: Fill in the description of the project for [http://rtime.felk.cvut.cz/gitweb/ GitWeb interface] &ndash; edit the file <tt>/var/git/''repo-name''.git/description</tt> on the server.
 
* [[Git#Install_Git|Install Git]] on your local computer
# Under Linux/Unix (or in Git Bash under Windows) run: <pre>ssh-keygen</pre>
* Put your sources into your local repository
# In Git Gui (under Linux or Windows) choose [[Media:Git-gui-key.jpg|Help -> Show SSH key -> Generate key]].
cd your/project
# Under Windows use PuTTYgen. Use this if you have chosen to [[Media:git-plink.jpg|use Plink]] during Git installation.
git init              # initializes git repository in your project's directory
 
It is stored by default at <tt>~/.ssh/id_rsa.pub</tt>.
 
=== Password-protected keys ===
 
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 passphrase, it will need to be entered whenever you want to push to or pull from the server. By using <tt>ssh-add</tt> command (or Pageant program under Windows) you can specify the passphrase only once and the decrypted key will be remembered in the memory.
 
== Creating repositories ==
 
There are two ways how a repository can be created:
 
# 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 (login or email) who should have access to the repository. The administrator creates the repository for you and notifies you when it's done.
# Our group staff members can create their repositories without asking the administrator. See below.
 
=== Automatic creation of repositories (staff members only) ===
 
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).
 
Such repository is by default accessible only to the creator. If you want this repository to be public, run
ssh git@rtime.felk.cvut.cz perms «login»/«whatever» + READERS @all
 
If you want to set a [https://rtime.felk.cvut.cz/gitweb/orte.git Gitweb description] for public repositories created this way, use gitolite's desc commands. I.e. you can set the description by:
ssh git@rtime.felk.cvut.cz desc «login»/«whatever» "Description"
 
== Accessing the repository ==
 
After [[Git#Install_Git|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
git clone http://rtime.felk.cvut.cz/git/''repo-name''.git
 
=== First push to admin-created repositories ===
 
After an empty repository is created by the admin, you can push (i.e. upload) the data to it:
 
* [[#Cloning the repository|Clone]] the empty 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
  git commit            # commits the added files to the repository
  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 ''login''@rtime.felk.cvut.cz:/var/git/''repo-name''.git
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
* Push your sources to the server
* Push your sources to the server
  git push --all
  git push
 
=== 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 branch ''your-branch''.


== How can other people access your repository ==
To make this behavior default run
git config remote.origin.push master:your-branch


Once the repository is not empty, 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):
And from now on, it is sufficient to run only
==== Central repository ====
  git push
  git clone ''login''@rtime.felk.cvut.cz:/var/git/''repo-name''.git
 
git clone git://rtime.felk.cvut.cz/''repo-name''.git
== Managing repositories ==
==== Personal repository ====
git clone git://rtime.felk.cvut.cz/~''yourlogin/''repo-name''.git


=== Finding available repositories ===


For other hints refer to the [http://git.or.cz/#documentation git documentation] or to [[Git|this page]].
You can find the list of repositories you have access to by running:


== Contributing to other projects ==
ssh git@rtime.felk.cvut.cz info [filter]
=== Forking projects hosted on this server ===


If you have an SSH account on this server, you can create a fork of any central git repository even if you do not have write permission to the repository. Fork is clone of other repository which references the cloned repository and disk space is not wasted. To create a fork just run:
where filter is optional string used to filter the list.


fork-git-repo /var/git/<repo-name>.git [ <name-of-fork> ]
=== Permissions to automatic repositories ===


If you omit name of fork, your login will be used instead.
The owners of automatically created repositories can manage the access permissions by themselves.


Example:
The current permissions can be listed by:
fork-git-repo /var/git/orte.git orte-fixes


Unlike personal repositories, forks can be [http://rtime.felk.cvut.cz/gitweb/orte.git/forks seen in gitweb interface].
ssh git@rtime.felk.cvut.cz perms -l «repo»


=== Using personal repository to contribute to other projects ===
You can add permissions for either reading of writing the repo with:
ssh git@rtime.felk.cvut.cz perms «repo» + READERS «login»
ssh git@rtime.felk.cvut.cz perms «repo» + WRITERS «login»


If you do not have write access to the repository of some project (not necessary a central repository on this server), you can work in your personal repository then ask somebody with write access to merge your changes.
The permissions can be removed by replacing '''+''' with '''-'''.


# Clone a central repository <pre>git clone git://rtime.felk.cvut.cz/project.git</pre>
To make your repository visible on [https://rtime.felk.cvut.cz/gitweb/ gitweb], run:
# Add your rtime personal repository as remote (using SSH access) <pre>git remote add personal yourlogin@rtime.felk.cvut.cz:myproject.git</pre>
ssh git@rtime.felk.cvut.cz perms «repo» + READERS @all
# Edit files in project...
# Commit your changes <pre>git commit ...</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>


== Links to git related documents ==


== Merging changes from forks ==
* [http://support.dce.felk.cvut.cz/mediawiki/index.php/gitolite Gitolite documentation on DCE IT pages]


git remote add fixes git://rtime.felk.cvut.cz/project/forkname.git
[[Category:Git]]
git fetch fixes (or git remote update)
git merge fixes/master

Latest revision as of 13:54, 12 April 2019

Repositories on rtime server are managed by Gitolite tool, which allows to conveniently manage repository permissions. World readable repositories can be browsed online.

In addition to gitolite repositories, users with shell account can create Git repositories in their home directory. This does not require any coordination with the administrator.

Getting write access to repositories

Write access to the repositories can only be given to users who send the following information to the administrator:

  1. OpenSSH public key
  2. Login name (for ČVUT people) or email address (for others).

SSH key creation

The SSH key can be created with one of the following ways. Note that under Windows, methods 1 and 2 only work if OpenSSH has been selected during Git installation.

  1. Under Linux/Unix (or in Git Bash under Windows) run:
    ssh-keygen
  2. In Git Gui (under Linux or Windows) choose Help -> Show SSH key -> Generate key.
  3. Under Windows use PuTTYgen. Use this if you have chosen to use Plink during Git installation.

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

Password-protected keys

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 passphrase, it will need to be entered whenever you want to push to or pull from the server. By using ssh-add command (or Pageant program under Windows) you can specify the passphrase only once and the decrypted key will be remembered in the memory.

Creating repositories

There are two ways how a repository can be created:

  1. Send an email to the administrator with the name of the repository, a short description and a list of people (login or email) who should have access to the repository. The administrator creates the repository for you and notifies you when it's done.
  2. Our group staff members can create their repositories without asking the administrator. See below.

Automatic creation of repositories (staff members only)

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).

Such repository is by default accessible only to the creator. If you want this repository to be public, run

ssh git@rtime.felk.cvut.cz perms «login»/«whatever» + READERS @all

If you want to set a Gitweb description for public repositories created this way, use gitolite's desc commands. I.e. you can set the description by:

ssh git@rtime.felk.cvut.cz desc «login»/«whatever» "Description"

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
git clone http://rtime.felk.cvut.cz/git/repo-name.git

First push to admin-created repositories

After an empty repository is created by the admin, you can push (i.e. upload) the data to it:

  • 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

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 branch 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

Managing 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.

Permissions to automatic repositories

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

The current permissions can be listed by:

ssh git@rtime.felk.cvut.cz perms -l «repo»

You can add permissions for either reading of writing the repo with:

ssh git@rtime.felk.cvut.cz perms «repo» + READERS «login»
ssh git@rtime.felk.cvut.cz perms «repo» + WRITERS «login»

The permissions can be removed by replacing + with -.

To make your repository visible on gitweb, run:

ssh git@rtime.felk.cvut.cz perms «repo» + READERS @all

Links to git related documents