Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Git Guide

Version Control and Collaborative Coding

Auteurs : NERON Francois


Version :1R0
Cursus : EENG3
Date : 29/03/2024
Titre du Polycopié

Historique

Version Date Auteur Nature des modifications

1R0 29/03/24 Neron Francois Création

2
Sommaire
Chapitre 1. Mode d’emploi du modèle .......................................................... Erreur ! Signet non défini.
1. Utilisation du modèle de document ........................................................ Erreur ! Signet non défini.
2. Mises en formes de caractères .............................................................. Erreur ! Signet non défini.
3. Mises en formes de paragraphes .......................................................... Erreur ! Signet non défini.
4. Tableaux: ............................................................................................... Erreur ! Signet non défini.
5. Objets courants : .................................................................................... Erreur ! Signet non défini.
5.1. Résumé : Style « Objet : Résumé » ................................................ Erreur ! Signet non défini.
5.2. Théorèmes et Démonstrations : Style « Objet : Théorème + Démonstration »Erreur ! Signet
non défini.
5.3. Figures : Style « Objet figure »........................................................ Erreur ! Signet non défini.
5.4. Algorithmes : Style « Objet : Algorithme » ...................................... Erreur ! Signet non défini.
5.5. Equations : Style « Objet : Equation » ............................................ Erreur ! Signet non défini.
6. Références bibliographiques ................................................................. Erreur ! Signet non défini.
7. Touches de raccourcis ........................................................................... Erreur ! Signet non défini.
Chapitre 2. Objet de l’étude ........................................................................... Erreur ! Signet non défini.
Chapitre 3. Références bibliographiques .................................................... Erreur ! Signet non défini.
Chapitre 4. Lorem ipsum ............................................................................... Erreur ! Signet non défini.
1. Lorem ipsum .......................................................................................... Erreur ! Signet non défini.
1.1. Lorem ipsum.................................................................................... Erreur ! Signet non défini.

3
Titre du Polycopié

A. What is Git

1. Git is a version control software.


Git is a software developed by Linus Torvald to handle version control, meaning the storage and
manipulation of files and folders that are changed, going through several versions of themselves.

The two first words you should get familiar with regarding git are:
 Repository:
o A Repository is a folder where git does its job of controlling version. It is just a folder
monitored by git, where it adds some data to do that monitoring in a “.git” subfolder.
 Commit:
o A commit is a group of modifications that make up the difference between two versions
of the repository.

Regarding our immediate need, the repository will be your java project.
Each time you modify your code and want to save its next (stable) state, you will do a commit.
Then, we will see how these commits can be shared between collaborators.

2. Repository synchronization

Git does not do automatic synchronization, like google doc or similar file sharing software.
You will need to know and launch yourself the two actions required:
 Push (from local to distant):
o Sends the commits that are in the local repository and not the distant to the distant
repository.
 The local repository is the one on your machine, your java project in our case
 The distant repository is another repository holding another version of the
same files.
 Pull (from distant to local):
o Gets the commits that are in the distant repository and not the local to the local
repository

4
B. Our Usecase: Git with Eclipse and Gitarero
You won’t have to install Git or use command lines to control it like it normally works!
A version of it is packaged with eclipse to use directly through the eclipse interface.
Additionaly, ECAM provides a git platform for shared distant repositories at the following address:
gitarero.ecam.fr

1. Create the distant repository

You must sign in on gitarero, using your ECAM identifiers.


Then, ONE of you should click the + button to add a new repository

In the following window, the only thing you need to do is add a name respecting the naming
convention used for the project :
OOP_<GroupName>_Project
AND
Uncheck the box “make repository private” ()

5
Titre du Polycopié

After clicking the validation button at the bottom of the page, you will get to a page looking like this :

Do not follow the instructions indicated in the page to create a repository (we will be using the Eclipse
embedded git, not command line)
The distant repository is now created.
You will need the copy button to the right of the HTTPS link to copy that link for later operations, but
now go into the settings cy clicking on the corresponding button.

6
In there, select the Collaborators pannel on the left to be able to Add collaborators by searching them
by name.
Add all the colleagues of your project group this way, and your professor if you want to enable us to
modify your code (for support at distance, for example)
Note : to be listed in gitarero, the user has to have already connected on that platform at least once, so
all your collaborators should have done so for you to be able to add them.

2. Only for the first collaborator: create the initial local repository.
Back in Eclipse, create a new project as usual:
Right click in Package explorer panel on the left (with your mouse not on a project or any of its content)
>New
>Java Project

7
Titre du Polycopié

In the project creation, make sure to add a name following the naming convention, make sure you
DON’T create a module-info.java, and (for compatibility reasons between different installations), select
the JRE version 1.8
Then you can click Finish.

Once this is done, we need to add a file in src


(git doesn’t count empty directories, and your colleages won’t be able to import the project from git if
src folder isn’t taken into account in git because of how Eclipse handles java projects)
To do so, just create some class you will remove later, or add the starting files of the project already.
Once you did that, right click on the name on the project in Package Explorer
>Team (this is the submenu used for everything related to git)
>Share Project (this will make a local repository from the project)

8
This will open this window :

If your project isn’t present and the only thing in the botton table, something is wrong.
If everything is correct, you can either
 click on the Create Button,
 or check the box “Use or create repository in parent folder of project”, then selecting the project
and clicking on the “Create Repository” button.
It isn’t the recommended option for real-world use cases (because of the pollution of the workspace
slowing down Eclipse, mostly), but for this project I would rather recommend the second option,
because it keeps your code files where you are used to having them.
Anyway, both will work.

9
Titre du Polycopié

Once this is done, you should see in the Package Explorer your project name has been expanded :

Now, if you go back to the Teams submenu when right-clicking the project name, you should see more
options:

Click on “Commit…”
This will open the Git Staging tab in Eclipse at the bottom, where the console usually is. You might need
to drag the top border of the bottom tab upwards to see more clearly.

10
In this, you have three boxes :
 Unstaged Changes
o These are the modifications git sees between the last version of your repository (the
initial version is considered empty, so at first all files in your project are considered to
have been added)
 Staged Changes
o These are the modifications you select to be saved as part of the next commit.
 Commit message
o Commits are required to be accompanied by a message describing how the commit
modifies the next version from the previous one. (what was added? What was fixed?)
To initialize the repository you must add all modifications to the stages changes (using the ++ button on
top of the unstaged changes), then write anything in the commit message box (“init repo”, for example).
Then you should click the “Commit” button. (not “Commit and Push” right away, as you will have to
specify the details on how to Push this first time, which is skipped by that button)
Once the commit is done, the button “Commit and Push becomes ”Push HEAD” (Head is just the name
of the last version in git). You can now click it.

11
Titre du Polycopié

If you have the link to your gitarero repository as the last thing you copied, it should autocomplete, if
not go back in your browser, get that link, and copy it here. (if you are still in the settings page, just click
on the name of the project on top in gitarero and it will bring you back to the main page of the gitarero
repository view), with this :

Once the link is copied in the push window in Eclipse, all fields should be autocompleted except those
in the Authentication area. There, use your Ecam identification (Eclipse will connect as you to the
repository on gitarero).
Check the box “Store in Secure Storage” if you want to avoid having to repeat giving your identification
to Eclipse all the time. (If you encounter problems with the secure storage, check the addendum at the
end of this file)
Once all is filled in, click Preview. You will have to click and wait a second for a certain number of times
before the Push button becomes available, then click the Push button.
You can go back to your browser, on the gitarero repository main page, and you should see the
instructions have been replaced by the list of the files (each file has as additional information the
message of the last commit that modified it, and the time since that commit was pushed)

12
3. Import the project from gitarero
This is to be done by all other members of the team, and any time you lose your local repo for some
reason.
In Eclipse, Right click in package explorer pannel then click on the “Import” option.
In the following window, select Git>Projects from Git, then click the “Next” button

Then click on “Clone URl”, and you will get a page very similar to the push destination selection page :

13
Titre du Polycopié

If you have the link to your gitarero repository as the last thing you copied, it should autocomplete, if
not go back in your browser, get that link, and copy it here.
As you aren’t the owner of the project, you might not have the link already, but you can search for its
name in the “Explore” section of gitarero

Once the link is copied in the window in Eclipse, all fields should be autocompleted except those in the
Authentication area. There, use your Ecam identification (Eclipse will connect as you to the repository
on gitarero).
Check the box “Store in Secure Storage” if you want to avoid having to repeat giving your identification
to Eclipse all the time. (If you encounter problems with the secure storage, check the addendum at the
end of this file)
Once all is filled in, click Next. You will have to click and wait a second for a certain number of times
before the Finish button becomes available, then click the Finish button.

14
You should see the new project in your Package Explorer. It is now in the same state as the one of your
collaborators who pushed last when he did.

4. Workflow
With everything properly configured, you can now commit your modifications to a local repository, then
push the commits to a distant shared repository on gitarero and pull you collaborator’s commits from
said distant shared repository after they pushed them there.
One golden rule to keep in mind :
 You only commit modifications if there are no errors inside them. By error I mean stuff that make
a red cross on the left in your Eclipse editor and break compilation
This is to avoid having a version of the code that you share with your collaborators and that breaks the
compilation for them, which would prevent them from being able to work, even if they work on
something far away in the code.

4.1. First, Pull


The push will only work if your commits start from the same version as the version on gitarero, so you
should always first update your local version. This is done by Right Click on project >Team>Pull (not
“Pull…”, except if you need to reconfigure the connection for some reason)
When you pull, if you have local non-commited modifications of files that should be modified by the
commits you are pulling, the pull wont work. Either remove your modification or commit them.
To remove modifications and revert a file to its state in the latest local commit, right click on it in the git
staging tab, and select “Replace with HEAD Revision”.
Warning: This is the only way you can really lose work you did! (but only the work you haven’t
committed!)

Now, if you have a local commit that modifies a file that is also modified by a commit you pull, this files
has a CONFLICT (as it has two conflicting versions). If the modifications are on different lines, git will
manage to automatically fix the conflict by MERGING the two modifications, fusing them together.
BUT…
If a conflict happens on a file between modifications on the same lines, git can’t know how to fuse the
modifications. It will add the two conflicting versions in that area of the file and you will have to solve
the conflict by replacing this conflicting area with whatever you find adequate, be it one of the two
versions, or something completely different, but you will then have to commit that modification, which
will be considered as the MERGE solving this conflict.
TO AVOID CONFLICTS:
Organize your work with your collaborators to avoid working at the same time on the same area of the
code. Regularly push your modifications, and ALWAYS pull : before you code, before pushing, in the

15
Titre du Polycopié

middle of your coding sessions… just globally pull modifications as frequently as you can if you know
your collaborators might be working at the same time, it can’t hurt.
(to avoid pushing and pulling to many things at once, which would increase the risk of a conflict)

4.2. To push :
Right-click on project name > Team>“Commit…”
This will open the Git Staging tab in Eclipse at the bottom, where the console usually is. You might need
to drag the top border of the bottom tab upwards to see more clearly.

In this, you have three boxes :


 Unstaged Changes
o These are the modifications git sees between the last version of your repository (the
initial version is considered empty, so at first all files in your project are considered to
have been added)
 Staged Changes
o These are the modifications you select to be saved as part of the next commit.
 Commit message
o Commits are required to be accompanied by a message describing how the commit
modifies the next version from the previous one. (what was added? What was fixed?)
To make a commit you must add all modifications you want to save to the staged changes (using the +
button on top of the unstaged changes for each one, or ++ for all at once), then write something
describing what your modification does in the commit message box (“fixed bug in Agent movement”,
for example).
Then you can click the, Commit, or “Commit and push” button (if the commit works but the push doesn’t,
your commit is still locally saved, and you will be able to push it later).

16
C. Addendum : How to remove stored
passwords from secure storage in case the stored
password is wrong:
Top bar > Window
> Preferences

This opens the Preferences menu. In the left options, select “General>Security>Secure Storage”
The center area should become this :

17
Titre du Polycopié

Inside which you should go in the Contents tab

18
Click on the “[Default Secure Storage]”>”GIT”. While this is selected, click the Delete button.

19

You might also like