Difference between revisions of "GIT/En"

From TuxFamilyFAQ
Jump to navigationJump to search
 
(11 intermediate revisions by 8 users not shown)
Line 1: Line 1:
<big>GIT repository</big>
+
<big>Git repository</big>
  
 
{{Template:Languages}}
 
{{Template:Languages}}
Line 6: Line 6:
 
= Description =
 
= Description =
  
[http://git.or.cz git] is an other team coding system such as [[CVS/En|CVS]] or [[SVN/En|SVN]]  
+
[https://git-scm.com/ git] is another team coding system such as [[CVS/En|CVS]] or [[SVN/En|SVN]]
  
= Dependences =
+
If you only want to run git from the command line, then git is all you need to install. <br />
 +
But there are optional Graphical User Interfaces (GUIs) available to help you, such as: <br />
 +
git-gui (git gui) - Helps with staging files for commit, writing commit messages, and pushing. <br />
 +
gitk - Helps with reviewing the history of git commits. <br />
  
*an [[User/En|user account]]
+
= Dependencies =
 +
 
 +
*A [[User/En|user account]]
 
*A [[Group/En|moderated project]]
 
*A [[Group/En|moderated project]]
  
= Creating the GIT repository =
+
= Creating the git repository =
  
*Go on the control panel
+
*Go to the control panel
*Select the project where you want to add a GIT repository
+
*Select the project where you want to add a git repository
 
*Choose the name of your repository
 
*Choose the name of your repository
 
*Validate
 
*Validate
Line 23: Line 28:
  
 
*Don't choose a too usual name
 
*Don't choose a too usual name
*Fill the description field to avoid problems with the moderation team ;)
+
*Fill in the description field to avoid problems with the moderation team ;)
  
 
= Moderation =
 
= Moderation =
Line 44: Line 49:
 
*Log into the panel
 
*Log into the panel
 
*click on the group corresponding to your project
 
*click on the group corresponding to your project
*click on your GIT repository
+
*click on your git repository
 
*click on destroy
 
*click on destroy
  
 
= How to use it =
 
= 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.
+
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==
 
== Basic Operations==
Line 63: Line 68:
 
  $ git push origin master
 
  $ 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.)
+
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...)
 
(Of course, replace YOURUSER, YOURPROJECT and REPOSITORYNAME by the real values...)
  
With git 1.6.2+, you can clone a empty repo:
+
With git 1.6.2+, you can clone an empty repo:
 
  $ git clone ssh://YOURUSER@git.tuxfamily.org/gitroot/YOURPROJECT/REPOSITORYNAME.git
 
  $ git clone ssh://YOURUSER@git.tuxfamily.org/gitroot/YOURPROJECT/REPOSITORYNAME.git
  
 
It'll complain, but it works.
 
It'll complain, but it works.
  
To download a full copy of your GIT repository, you can use the clone command:  
+
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
 
  $ git clone ssh://YOURUSER@git.tuxfamily.org/gitroot/YOURPROJECT/REPOSITORYNAME.git
Line 114: Line 119:
  
  
==== Updating your repository ====
+
==== Updating your local copy of the repository ====
When working in team, it can be useful to update the local copy of your repository :
+
When working in a team, it can be useful to update the local copy of your repository :
 
  $ git pull
 
  $ git pull
 
  '''Warning''': You might have to type the password several times
 
  '''Warning''': You might have to type the password several times
  
== Using GIT as an anonymous user ==
+
== 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).
+
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 :
 
To make an anonymous checkout, type this :
 
  $ git clone git://git.tuxfamily.org/gitroot/YOURPROJECT/YOURREPOSITORY.git
 
  $ git clone git://git.tuxfamily.org/gitroot/YOURPROJECT/YOURREPOSITORY.git
  
Anonymous people can also check for new versions by typing :
+
Anonymous people can also check for updates by typing :
 
  $ git pull
 
  $ git pull
  
 
The anonymous mode is set on the panel (default=allowed)
 
The anonymous mode is set on the panel (default=allowed)
  
== Using Gitweb ==
+
== Using CGit ==
  
 
You can see your all the public repositories here : http://git.tuxfamily.org
 
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 )
+
URLs will look like this : http://git.tuxfamily.org/group/repository.git/ ( http://git.tuxfamily.org/tftest/testgit.git/ for example )
 +
 
 +
=== How to keep in touch with your repository ===
 +
 
 +
It is possible to monitor branches in your repository using CGit's Atom feed.
 +
 
 +
  http://git.tuxfamily.org/group/repository.git/atom/?h=master
 +
 
 +
( http://git.tuxfamily.org/tftest/testgit.git/atom/?h=master for example )
 +
 
 +
Or monitor all branches.
 +
 
 +
  http://git.tuxfamily.org/group/repository.git/atom/?all=1
 +
 
 +
( http://git.tuxfamily.org/tftest/testgit.git/atom/?all=1 for example )
  
 
== Configuring SSH in GNU/Linux ==
 
== Configuring SSH in GNU/Linux ==
Line 157: Line 176:
  
 
===Using ssh-agent/keychain===
 
===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.
+
So far we have not improved the situation very much, since, instead of TuxFamily's password, your key's passphrase will be asked each time you 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).
+
Fortunately there are programs which allow you to manage your SSH keys, so that you will have to type your passphrase just once per session (or, in case of keychain, just once per boot).
  
 
====ssh-agent====
 
====ssh-agent====
 
The first option is to use ssh-agent.
 
The first option is to use ssh-agent.
  
Désormais il ne reste plus qu'à lancer une session SSH sur votre machine. Ceci se résume en 2 commandes. Tout d'abord (au cas où) il faut "killer" tous les processus ssh-agent si vous en avez lancé un. Sachez qu'il faut toujours verifier que aucun autre agent ssh soit lancé car Gnome et d'autres environnements lancent un agent.
+
This uses 2 commands, but first you must kill any existing agents:
 
  $killall ssh-agent
 
  $killall ssh-agent
  
Puis nous allons lancer les 2 commandes qui vont permettre à votre machine de communiquer avec GIT via SSH.  
+
Now you may run these commands to start a new agent and register the SSH key with the agent.  
 
  $ ssh-agent $SHELL
 
  $ ssh-agent $SHELL
 
  $ ssh-add ~/.ssh/id_rsa
 
  $ ssh-add ~/.ssh/id_rsa
  
Si tout s'est bien passé, vous n'aurez pas à taper votre mot de passe à chaque commande GIT que vous ferez par la suite. A chaque fois que vous voudrez utiliser cvs, il faudra ouvrir une session SSH:
+
To make this happen automatically when you start a shell:
$ ssh-agent $SHELL
 
$ ssh-add  ~/.ssh/id_rsa
 
Et toute les commandes GIT devront être tapées dans le même SHELL.
 
 
 
Pour éviter de devoir ouvrir une session à la main à chaque session, ajoutez ces lignes dans le fichier .bashrc :  
 
 
  if [ -f .ssh-agent ]; then
 
  if [ -f .ssh-agent ]; then
 
  .ssh-agent
 
  .ssh-agent
Line 204: Line 218:
 
  fi
 
  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.
+
In case you are wondering, the "if" statement makes sure you are in an interactive shell before launching keychain and reading the environment variables.
  
  
 
Please refer to the keychain homepage for more documentation.
 
Please refer to the keychain homepage for more documentation.
  
==Développement collaboratif, droits d'écriture==
+
== Pushing to the Git repository on git.tuxfamily.org ==
Tous les utilisateurs du groupe auront la permission d'écrire sur le GIT. Autrement dit, si vous désirez développer à plusieurs sur un même repository, il est conseillé d'ajouter les développeurs au groupe via le panel. Toutefois, il faut que les développeurs se créent un compte sur le panel au préalable.
+
 
 +
You can access it by ssh but not by the git protocol (git://):
 +
 
 +
$ git push ssh://'USER'@git.tuxfamily.org/gitroot/'PROJECT'/'REPOSITORY'.git master
 +
 
 +
=== git config of the tuxfamily's repository ===
 +
 
 +
The git-config's options receive.denyDeleteCurrent and receive.denyNonFastForwards seem to be set, so you will not be able to delete anything from the branch 'master'.  It is however still possible to delete other branches or tags:
 +
 
 +
$ git push ssh://'USER'@git.tuxfamily.org/gitroot/'PROJECT'/'REPOSITORY'.git "":devel
 +
 
 +
If you want to delete from the master branch once (for example because of a mistake), you can make sure that you have a backup of the repo, then delete it, wait for the deletion to be effective, recreate it and finally push the backup to it (without the unwanted commits of course). If you would like to regularly rebase or delete the branch 'master' you can contact an admin so that it can disable these options on your repository or, better still, implement a configuration of this option through the panel in VHFFS (see https://www.vhffs.org/dev:mainpage).
 +
 
 +
== Collaborative development, Write access ==
 +
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 git repository.
  
Un projet correspond à un groupe (au sens Unix du terme), il faut ajouter vos co-développeurs à votre projet pour qu'ils puissent commiter des modifications au dépôt subversion (ils auront aussi accès à l'arborescence, permettant de maintenir l'intégralité du projet collaborativement).
+
Otherwise, you may get an error message similar to the following:
  
Autrement, vous risquez d'obtenir le message suivant :
+
error: unable to create temporary sha1 filename ./objects/tmp_obj_9tDId6: Permission denied
  <a remplir en cas d'echec de droits>
+
 +
fatal: failed to write object
 +
  unpack unpacker exited with error code
 +
ng refs/heads/master n/a (unpacker error)
 +
error: failed to push to 'ssh://xxx@git.tuxfamily.org/gitroot/yyy/zzz.git'
  
 
= Tricks and tips =
 
= 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.
+
*We recommend committing only code that compiles correctly (even if it doesn't work completely) to always be sure that the repo 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~.
+
*You have to choose the files you want to put on your git repository. It is not necessary to upload backup files, or binary 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...
 
*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 =
 
= Useful links =
 +
https://git-scm.com/book/en/v2 Free book: Pro Git, by Scott Chacon and Ben Straub <br />
 +
https://ndpsoftware.com/git-cheatsheet.html Git Cheatsheet <br />

Latest revision as of 23:21, 10 November 2019

Git repository




Description

git is another team coding system such as CVS or SVN

If you only want to run git from the command line, then git is all you need to install.
But there are optional Graphical User Interfaces (GUIs) available to help you, such as:
git-gui (git gui) - Helps with staging files for commit, writing commit messages, and pushing.
gitk - Helps with reviewing the history of git commits.

Dependencies

Creating the git repository

  • Go to 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 in 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 local copy of the repository

When working in a 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 updates by typing :

$ git pull

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

Using CGit

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

How to keep in touch with your repository

It is possible to monitor branches in your repository using CGit's Atom feed.

 http://git.tuxfamily.org/group/repository.git/atom/?h=master

( http://git.tuxfamily.org/tftest/testgit.git/atom/?h=master for example )

Or monitor all branches.

 http://git.tuxfamily.org/group/repository.git/atom/?all=1

( http://git.tuxfamily.org/tftest/testgit.git/atom/?all=1 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 have not improved the situation very much, since, instead of TuxFamily's password, your key's passphrase will be asked each time you use Git.

Fortunately there are programs which allow you to manage your SSH keys, so that you will have to type your 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 and reading the environment variables.


Please refer to the keychain homepage for more documentation.

Pushing to the Git repository on git.tuxfamily.org

You can access it by ssh but not by the git protocol (git://):

$ git push ssh://'USER'@git.tuxfamily.org/gitroot/'PROJECT'/'REPOSITORY'.git master

git config of the tuxfamily's repository

The git-config's options receive.denyDeleteCurrent and receive.denyNonFastForwards seem to be set, so you will not be able to delete anything from the branch 'master'. It is however still possible to delete other branches or tags:

$ git push ssh://'USER'@git.tuxfamily.org/gitroot/'PROJECT'/'REPOSITORY'.git "":devel

If you want to delete from the master branch once (for example because of a mistake), you can make sure that you have a backup of the repo, then delete it, wait for the deletion to be effective, recreate it and finally push the backup to it (without the unwanted commits of course). If you would like to regularly rebase or delete the branch 'master' you can contact an admin so that it can disable these options on your repository or, better still, implement a configuration of this option through the panel in VHFFS (see https://www.vhffs.org/dev:mainpage).

Collaborative development, Write access

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 git repository.

Otherwise, you may get an error message similar to the following:

error: unable to create temporary sha1 filename ./objects/tmp_obj_9tDId6: Permission denied

fatal: failed to write object
unpack unpacker exited with error code
ng refs/heads/master n/a (unpacker error)
error: failed to push to 'ssh://xxx@git.tuxfamily.org/gitroot/yyy/zzz.git'

Tricks and tips

  • We recommend committing only code that compiles correctly (even if it doesn't work completely) to always be sure that the repo 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 binary 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

https://git-scm.com/book/en/v2 Free book: Pro Git, by Scott Chacon and Ben Straub
https://ndpsoftware.com/git-cheatsheet.html Git Cheatsheet