Activity Team/Git Tutorial

Team Home   ·   Join   ·   Contacts   ·   Resources   ·   FAQ   ·   Roadmap   ·   To Do   ·   Meetings


Gitorious

Getting started with Gitorious, a web based Git service provided by Sugar Labs.

You will learn to:

  • create an account, which you do once,
  • create and add an SSH key, which you do once or if you change system,
  • create a project, a local repository, and identify yourself to git, which you do once per project,
  • add source files, change existing source files, commit changes, push changes, and pull changes, which you do regularly.


Create an Account

Create an account on git.sugarlabs.org by selecting the Register link on the page. You will be asked:

  • Login
  • Email
  • Password
  • Password Confirmation

Fill the fields and press SIGN UP. Gitorious will send you a confirmation email. Check your email, wait for the confirmation, and follow the link provided.

Once you do this, Gitorious knows who you are and how to contact you. You should only need to do this once.


Create SSH Key

Skip this section if you already have an SSH key in .ssh directory that you trust.

To create a key use ssh-keygen. The following command will create a “dsa” key:

ssh-keygen -t dsa

For creating a “rsa” key use:

ssh-keygen -t rsa

The key will be stored as two files in the hidden .ssh directory.

id_dsa.pub is your public key. id_dsa is your private key. Only you should have access to this private key. Access to the key will grant access to Gitorious in your name. For example, here is a list of files in the .ssh directory of user strom:

ls -al ~/.ssh
-rw-------   1 strom strom  668 2009-12-17 21:51 id_dsa
-rw-r--r--   1 strom strom  603 2009-12-17 21:51 id_dsa.pub

You should only need to create a key once, unless you change to another system, or you think your private key was compromised. If you do it again, you must also add the new key to Gitorious in the next section.


Add SSH Key

Log in to http://git.sugarlabs.org/ click on Dashboard, then Manage SSH, then Add SSH key. The Add a new public SSH key page will appear, with a large text entry field. Open your public key in a text editor or web browser, and then paste it into the text entry field. Click on Save.

Once you do this, Gitorious trusts SSH connection from your system because your system has the private key, and Gitorious has the public key. You should only need to do this once, unless you change to another system.

(With ssh-keygen you can specify the name of your key file. Using this feature is not a good idea, because we haven't tested it. Keys should generally be located in ~/.ssh/id_rsa.pub or ~/.ssh/id_dsa.pub.)

ToDo: Does keys protected with a passphrase work together with GIT?

ToDo: What is the difference between DSA and RSA keys?

  • until the patent expired, RSA could not be used in some countries,
  • some countries have laws against consumer use of encryption.


Create a Project

Check that the activity is not already on git.sugarlabs.org. If it is, note the clone URL and skip to the next section. If it is not, then click the Create a new project link on the Projects page, and enter:

  • Title
  • Slug (this defaults to a file name format of your title)
  • License
  • Description

then click on Create project. There several other question which can be answered later as you have more information.

Once this step is done, Gitorious will have created a git repository at Sugar Labs. You must only do this once for each project.


Create Local Repository

Clone it from Gitorious:

git clone gitorious@git.sugarlabs.org:${SLUG}/mainline.git ${SLUG}.git

Replace ${SLUG} substring with your project slug value.

Once you do this, you will have a local repository that shares the same history of changes (if any) of the repository at Sugar Labs. You should only need to do this once for each project and system. You can do it again if you need a fresh copy that has no changes.


Identify Yourself to Git

Git on your local system must know your email and name. It uses this when you commit a change, so that when you push or mail it others will know who did it.

If you do not use git on your system for any other project, you can configure git:

git config -f ~/.gitconfig user.email <email-you-used-for-registering-project>
git config -f ~/.gitconfig user.name <your-name>

You should only need to do this once on a system.

Otherwise, configure git in the repository:

cd ${SLUG}
git config user.email <email-you-used-for-registering-project>
git config user.name <your-name>

You should only need to do this once in a repository.


Develop

Use a text editor or integrated development environment to create new source files or change existing files. Test the results by running the activity. Repeat until you are satisfied with the changes you made.


Commit Changes

Find out from git what files you changed:

git status

Add any files that are new or changed:

git add ...

Tell git to collect the changes into a commit:

git commit

You should do this for every meaningful set of changes you make.


Request Review

Before you publish changes widely, you can ask others to review your work and comment on it.

git format-patch -1

or

git send-email

You may do this for every set of changes you make.


Push Changes

Your changes have to be pushed from your local repository to the repository at git.sugarlabs.org so that others can see them there.

git push

You must do this for every set of changes you make, when you want to synchronise with other developers or prepare for a release.


Pull Changes

Others, including pootle, may add changes to the repository at git.sugarlabs.org. You must merge these with your repository.

Use

git-pull

Also, run

python setup.py fix_manifest

to update the .mo files after updating the .po files

You should do git pull frequently; before starting development, before pushing changes, and when you see other developers commit changes.


Other Notes

Tags

alsroot taught me about another git feature: tags

git tag -m "Release 36" v36 HEAD
git push --tags

What Pull Does

bertf explained to me that git-pull does a combination of fetch and merge, so to merge a patch...

git pull git://git.sugarlabs.org/infoslicer/alsroots-clone.git master

Moving to Sugar Labs

A few notes re moving to the Sugar Labs infrastructure:

  • use git init to create a new project unless it already exists.
  • use setup.py dist_source to make the source package associated with your project.
  • source packages now go in:
download.sugarlabs.org:/srv/www-sugarlabs/download/sources/
from there, if your project (if it is an Activity) probably belongs in the honey subdirectory, e.g.,
download.sugarlabs.org:/srv/www-sugarlabs/download/sources/honey/Abacus/
If your project is part of the Sugar core, it goes in sucrose/fructose/ (for core Activities) or sucrose/glucose (for core modules), e.g.,
download.sugarlabs.org:/srv/www-sugarlabs/download/sources/fructore/TurtleArt/
download.sugarlabs.org:/srv/www-sugarlabs/download/sources/glucose/sugar-toolkit/
  • don't forget to update addons as well!!
  • and to copy the tar file to download.sugarlabs.org
download.sugarlabs.org:/download/sources/honey/...
download.sugarlabs.org:/download/sources/sucrose/fructose/...