GIT/En

From TuxFamilyFAQ
Jump to: navigation, search

GIT repository




Contents

Description

git is an other team coding system such as CVS or SVN

Dependences

Creating the GIT repository

  • Go on the control panel
  • Select the project where you want to add a GIT repository
  • Choose the name of your repository
  • Validate

creating tips

  • Don't choose a too usual name
  • Fill the description field to avoid problems with the moderation team ;)

Moderation

Your repository will be subject to moderation, see here

How to administrate it (panel)

On the panel you can choose if you want the repository to be public. By accepting it, you allow a read-only anonymous login on the repository and you allow viewing it from the gitweb.

Configuration

How to handle group rights

This object can be shared with your group using the ACL

How to destroy it

  • Log into the panel
  • click on the group corresponding to your project
  • click on your GIT repository
  • click on destroy

How to use it

So, you've chosen to be hosted by TuxFamily, that's good. You chose a GIT repository, that's great ! We're going to teach you how to use it.

Basic Operations

Check out

Start by creating a local version of your repository. We will assume that you already have a directory with your project inside.

$ cd myproject
$ git init
$ git add myfirstfile mysecondfile
$ git remote add origin ssh://YOURUSER@git.tuxfamily.org/gitroot/YOURPROJECT/REPOSITORYNAME.git
$ git commit -a
$ git push origin master

This will create the first commit that will be the 'master' branch of your GIT repository. (When your first push is done, you use "git push" normally.)

(Of course, replace YOURUSER, YOURPROJECT and REPOSITORYNAME by the real values...)

With git 1.6.2+, you can clone an empty repo:

$ git clone ssh://YOURUSER@git.tuxfamily.org/gitroot/YOURPROJECT/REPOSITORYNAME.git

It'll complain, but it works.

To download a full copy of your GIT repository, you can use the clone command:

$ git clone ssh://YOURUSER@git.tuxfamily.org/gitroot/YOURPROJECT/REPOSITORYNAME.git
remote: Generating pack...
remote: Done counting 6 objects.
remote: Deltifying 6 objects...
remote: (6/6) done
remote: Total 6 (delta 0), reused 0 (delta 0)
Indexing 6 objects...
100% (6/6) done

Adding, removing files, updating your repository

Adding files

Go into your local repository

$ cd repos

let's create a file named 'file'

$ touch file

Then to add the file to your repository, just type :

$ git add file

Now, you can commit by typing :

$ git commit file

Once the commit is done, you can push everything on the server :

$ git push

For directories, we will do the same

$ git add directory/
$ git commit directory/
$ git push

Removing a file

To remove a file, just type :

$ git rm file
$ git commit
$ git push


Updating your repository

When working in team, it can be useful to update the local copy of your repository :

$ git pull
Warning: You might have to type the password several times

Using GIT as an anonymous user

You can use GIT without logging in. You won't be able to change the repository (add or remove files). To make an anonymous checkout, type this :

$ git clone git://git.tuxfamily.org/gitroot/YOURPROJECT/YOURREPOSITORY.git

Anonymous people can also check for new versions by typing :

$ git pull

The anonymous mode is set on the panel (default=allowed)

Using Gitweb

You can see your all the public repositories here : http://git.tuxfamily.org URLs will look like this : http://git.tuxfamily.org/group/repository/ ( http://git.tuxfamily.org/tftest/testgit/ for example )

Configuring SSH in GNU/Linux

TuxFamily uses Git in conjunction with SSH. This means that every time you access your repository with Git, you will have to type in your TuxFamily password to authenticate. This can become quite annoying and cumbersome.

It is possible to use SSH keys in conjunction with software like ssh-agent and keychain to provide a much more comfortable user experience, without sacrificing security.

Creating and uploading the SSH key

To use an SSH key, first of all you have to create such key. To create an SSH key open a console an type:

$ ssh-keygen -t rsa

You will be asked to type a passphrase. Once you have entered your passphrase, the key is ready to be used.

A pair of keys has been generated with the above command: your private key, which you must keep secret for yourself, and your public key, which we are going to upload to TuxFamily's server.

Your public key is named id_rsa.pub and it is placed, on creation, in your home directory under the ".ssh" subdirectory. With the following command we will copy your public key into a file called "ssh_keys" in your home directory:

$ cat ~/.ssh/id_rsa.pub >> ~/ssh_keys

Next we have to fix the permission on this copy of the public key, which will be uploaded to TuxFamily's server:

$ chmod 700 ~/ssh_keys

Finally, you will have to upload the "ssh_keys" file to TuxFamily's server using FTP. You can use any FTP client. The name of the FTP server is ftp://ftp.tuxfamily.org/ (you will have to enter your TuxFamily username and password). The "ssh_keys" file must be placed inside the root directory, i.e., the directory you will find yourself in after you connect to the FTP server.

Using ssh-agent/keychain

So far we do not have improved the situation very much, since, instead of TuxFamily's password, our key's passphrase will be asked each time we use Git.

Fortunately there are programs which allow to manage our SSH keys, so that we will have to type our passphrase just once per session (or, in case of keychain, just once per boot).

ssh-agent

The first option is to use ssh-agent.

This uses 2 commands, but first you must kill any existing agents:

$killall ssh-agent

Now you may run these commands to start a new agent and register the SSH key with the agent.

$ ssh-agent $SHELL
$ ssh-add ~/.ssh/id_rsa

To make this happen automatically when you start a shell:

if [ -f .ssh-agent ]; then
.ssh-agent
else
killall ssh-agent
ssh-agent > .ssh-agent
ssh-add ~/.ssh/id_rsa
fi

keychain

Keychain[1] is a SSH key manager that lets you load your SSH keys once per machine boot (i.e., keychain will not exit when you logout, it will sit silently in the background). Keychain uses ssh-agent internally.

Using keychain is a two stage process. First you start it, telling it to load your public key into memory:

$ keychain ~/.ssh/id_rsa

You will have to type in your key's passphrase. Then you have to read some environmental variables from a file. You can do this with the command

$ source ~/.keychain/`hostname`-sh

While you have to start keychain only once per machine boot, you will have to read the environmental variables each time you start a console session. To avoid this step, you can add something like this at the end of your ".bashrc" file (assuming you are using the bash shell):

if [[  $- != *i* ]] ; then
  # Shell is non-interactive.  Be done now!
  return
else
  keychain --nolock ~/.ssh/id_rsa
  source ~/.keychain/`hostname`-sh
fi

In case you are wondering, the "if" statement makes sure you are in an interactive shell before launching keychain an reading the environment variables.


Please refer to the keychain homepage for more documentation.

Development collaborative, writable

All users group will have permission to write to the GIT. In other words, if you want to develop more on a single repository, it is advisable to add developers to the group through the panel. However, it is necessary that developers create an account on the first panel.

A project is a group (within the meaning of the word Unix), add your co-developers to your project so they can commit on changes to the subversion repository (they will also have access to the tree, helping to maintain the entire project collaboration).

Otherwise, you may get the following message:

 <a completed in the event of d'echec droits>

Tricks and tips

  • We recomand committing only code that compile correctly (even if it doesn't work completely ) to always be sure that the trunk can be used by new users at any time.
  • You have to choose the files you want to put on your GIT repository. It is not necessary to upload backup files, or binaries files. Be careful, some text editors make automatic backups in xxx~.
  • Please don't choose a generic name for your repository such as "git". Instead, choose an intelligent name or in the worse case, use your project name...

Useful links