Overview

If you haven’t yet configured your local computer to be able to use the EPFL GitLab using your own ssh key, set up GitLab according to the GitLab setup manual. If you have already done that, skip to the Workshop section.

Workshop

This workshop aims to simulate working on a project with team members using git.

Our goal: just_do_git.py is a program that just prints I love git!. However, as a simple feature, we want it to display I <3 git!

Your team members will be bots that simulate working on the project, by doing merge requests, merging your changes, etc…

Note: If you follow this instruction, everything you add to the just do git - lab repository will be publicly visible. If you want to delete your branch and thus your changes at the end of the workshop, follow the cleanup section at the end of this page.

Access to Repository

  1. Go to the just-do-git group on the EPFL GitLab: gitlab.epfl.ch/gnugen/just-do-git

  2. Request access to the just-do-git group on GitLab. Click on the 3 dots on the top right and click request access.

Example: Requesting access.

A bot will invite you to a repository automatically ~30 seconds after clicking request access. Refresh the page after waiting ~30 seconds and you will see your personal lab repository.

  1. Clone the repository

     git clone YOUR_REPOSITORY
    

Replace YOUR_REPOSITORY with the SSH remote URL. You can find it out by clicking the blue Code button on the top right of your lab repository.

Make sure to clone with SSH not HTTP, so in the form of git@gitlab.epfl.ch:gnugen/just-do-git/git-lab_2026spring_7568.git!

Git Workflow

The workflow in our repository is structured in the following way:

You are the team leader and thus maintain develop branch, this is non-production code which your team merges features and fixes into.

At the same time, you also create a new feature in a feature branch named feature/FEATURE_NAME, that you want to merge into your develop branch.

Along the way there will be some complications, your digital team members (our bot) will make your life a bit difficult ;)

To summarize (you will replace the variables in caps later with your own feature description):

  • main: stable branch that contains production-ready code. Managed by gnugen
  • develop: integration branch where new features and fixes are merged before being released. Managed by you and our bot
  • feature/FEATURE_NAME: temporary branch created from develop to build and test a specific new feature or change. Managed by you

Our setup is heavily inspired by the GitFlow workflow

The Develop Branch

  1. Create your own develop branch locally

     git checkout -b develop
    
  2. Push your branch to the remote, check if it is visible in the GitLab UI

👀 Need a hint for 2? - Click here to reveal a hint

Try the following command and use the commands it proposes:

git push

Is your branch visible in GitLab? If yes, congratulations! Advance to the next step.

Development branch visible in GitLab

The Feature Branch

We create a new feature to replace the output of or just_do_git.py application

  1. Create your own feature branch locally (you can name it differently feature/improve_script_output_format is just a placeholder - but make sure it starts with feature/)

     git checkout -b feature/improve_script_output_format
    
  2. Push the branch to the remote (analogous to the develop branch)
  3. We add our feature in the code
    • Edit just_do_git.py
    • Replace love with <3
    • Change nothing else
  4. Display your changes in the command line

     git diff
    
  5. Now, stage, commit and push your changes
👀 Need a hint for 5? - Click here to reveal a hint

Try the following command and use the commands it proposes:

git status

Reload GitLab, do you see your changes? If yes, everything went well, advance to the next step.

The commit is visible with the comment just_do_git.py: output: change 'love' to '<3'

Merging

As you added your feature to the feature branch, is now time to merge your changes into develop.

We can either create a merge request on GitLab or use the command line to merge the branches. As the command line is way more fun, we will do it that way.

  1. Go to the develop branch and pull potential changes from your team (the bot).

     git checkout develop
     git pull
    
     Updating 1cc78fc..c11576d
     Fast-forward
      just_do_git.py => i_love_git.py | 0
      1 file changed, 0 insertions(+), 0 deletions(-)
      rename just_do_git.py => i_love_git.py (100%)
    
    • We see that a change occurred: just_do_git.py was renamed to i_love_git.py.
  2. Merge feature/improve_script_output_format into develop. For this merge to work the your feature branch has to be updated with the newest commits from develop (keyword: rebase). This will be a bit tricky as the file we made the changes to no longer exists.

    Hint: No merge conflict has to be resolved, and no other commits have to be made if done correctly.

👀 Need a second hint for 2? - Click here to reveal a hint

Before the merge, switch back to the feature branch and update it to the current state of develop using rebase. You have to force-push your changes here. Do you know why?

git checkout feature/improve_script_output_format
git rebase develop
git push -f

Check the history of the develop branch in GitLab, you should have the commits of your feature branch, as well as the bots feature branch. If this is the case, advance to the next step.

All commits are visible

Another Merge Request

Just as you solved your previous problem with a rebase, somebody else decides to edit the exact same line you did and create a merge request.

In this scenario (because of our bot setup), you don’t have write access to the feature branch that will be merged. Assume the maintainer of the branch is on vacation and forgot to unprotect their branch (give you access to it).

You were assigned said merge request on GitLab:

The merge request on the GitLab interface.

Let’s solve the problem locally for some git practice!

  1. Checkout to the develop branch

    Make sure to pull and fetch as needed.

  2. Merge the branch feature/replace_love_with_heart using the git merge command.
    1. An error message will appear:

       Auto-merging i_love_git.py
       CONFLICT (content): Merge conflict in i_love_git.py
       Automatic merge failed; fix conflicts and then commit the result.
      
      
    2. Edit i_love_git.py to solve the conflict.

    3. Once you edited i_love_git.py, you need to complete your merge. Stage your file, commit your changes and finally push to the remote.

👀 Need a hint for 2.2? - Click here to reveal a hint

Remove the headers and footers git added and delete the line you don’t want to keep.

In the end, the file should look normal, this means without <<<<<<< HEAD:i_love_git.py, =======, etc…

👀 Need a hint for 2.3? - Click here to reveal a hint

Type the following command, which will give you suggestions on what to do:

git status

Check the state of your merge request in GitLab, it should not have any conflict anymore! But as you already merged it manually, you can close the request

The merge request on the GitLab interface.

If you made it this far: congrats!

This is the end of the (git-)lab ;)

You successfully collaborated with your team to create a new version of just_do_git.py and solved 2 merge conundrums!

Now, you can create your own repositories and experiment with git on your own. Or create a repository for your actual projects at EPFL.

If you want to instead to improve your git skills using a game, we suggest Oh My Git!

  • open ohmygit.org
  • click on the button labelled “Download the game!” below “Play the game!”
  • and follow the instructions for your OS

Survey

We value your feedback!

To make the workshop even better next year, feel free to fill out this survey so we know if you liked the workshop and how we can improve it.

It only takes 2 minutes to fill out and helps us a lot! :))