Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lab1: Discovering Git

IUT d'Orsay, Université Paris-Saclay

Objectives

The goal of this lab is to understand the following concepts and commands:

Introduction to version control

Getting started with Git

  1. Create a new directory named qualite-dev-s2-<first-name>-<last-name> by replacing <first-name> and <last-name> with your first name and last name (for example, qualite-dev-s2-hoang-la).

  1. Go to this new directory and create a file named my-first-file.txt by running the following command.

touch my-first-file.txt
  1. Edit my-first-file.txt using the editor of your choice and add the following line: Hello World!

We now want to save this first version of our project.

  1. Run the following command.

git init
  1. Run the following commands, replacing the information with your own.

git config --global user.name "<First name> <Last name>"
git config --global user.email "<University email>"

For example:

git config --global user.name "Hoang La"

Then:

git config --global user.email "hoang.la@universite-paris-saclay.fr"

Three states of the same directory

  1. Run the following command. What do you observe?

git status
  1. Run the following command.

git add my-first-file.txt
  1. Run the following command. What do you observe?

git status
  1. Run the following command.

git commit -m "The first version of my project"
  1. Run the following command.

git log

The three states of the same directory.

  1. Run the following command and observe the result.

git status

Adding and unstaging changes

  1. Modify the contents of my-first-file.txt by replacing the line Hello World! with Hi World!.

  2. Create a second file my-second-file.txt and add the line Hi there! to it.

  3. Add all changes using one of the following commands.

git add my-first-file.txt my-second-file.txt

or

git add .

Imagine that you made a mistake and that you no longer want to keep Hi World! in my-first-file.txt. Even if the modification is tracked (present in the Staging Area), it is not too late!

  1. Run the following command.

git restore --staged my-first-file.txt

It is now time to save the second version of your project.

  1. Run the following command.

git commit
  1. Write your commit message on the first line.

If you are using the Nano editor (which looks like the screen above):

If you are using the Vim editor (the default editor on Debian at the IUT):

You now have a second version of your project in the version history. The version stored in the Local Repo therefore contains the files my-first-file.txt and my-second-file.txt with the lines Hello World! and Hi There! respectively, while the “draft” version in your Working Tree contains the line Hi World! in my-first-file.txt.

To conclude…

Let’s finish this lab with a small reorganization.

  1. Create a Lab1/ directory as a subdirectory of your project root.

  1. Move everything (except .git/) into the Lab1/ directory.

You will maintain this project for the rest of the course by creating separate subdirectories for each lab.

  1. Go back to the project root and run git add .

  1. Commit the tracked changes using git commit.

  1. Go back to the objectives and check the points you have mastered. Practice the commands and concepts you have not fully understood yet. Ask your instructor for help if needed.