Git Fetching Exercises Solutions - EPFL-MICRO-315/TPs-Wiki GitHub Wiki
🐈 Introduction
This page explains how to fetch the lab exercises and their corresponding solutions from the reference repository on GitHub. This is typically done through fetching a new remote branch and pulling its content locally. Few notes:
- The lab solutions will be released the week after you started working on the corresponding exercise;
- On week 1, you will not have a local copy of the solutions nor the exercises when you first clone your repository;
- To acquire the new exercises and/or solutions, you will have to regularly fetch the reference repository https://github.com/MICRO-315/TPs-Student/ to download the solutions or the new exercises, as explained in this wiki;
- The setup you should already have on your machine is as follows, with fetching access on TPs-Student and fetching/pushing access to the tps-et-miniprojet-group-xxx-yyy repository. If this is not the case, make sure you have set up your local git repository correctly.
If you learn better through videos, feel free to watch the following one that sums up how to fetch solutions (but it works the same for exercises) and then digs deeper on how to compare your code with this solution:
⚠ Pre-requisit
Make sure you have followed the procedure of setting up git for the labs. You should now have a local git directory and added the remote reference to your local repository.
This wiki uses the git extension of VSCode to handle git commands more easily. Make sure you're comfortable with basic git methodology and its handling in VSCode.
👉 Fetching and pulling remote branches
- First,
Fetch From All Remotesin order to fetch all new available branches on all remotes (in your case there should be two remotes: origin and reference); - ⚠ BEFORE checking out anywhere, you must have no pending modifications (neither staged nor unstaged). Otherwise you must either
commit,discardorstashthose modifications; - Checkout to the new branch that you would like have locally, here
TP2_Exercisefor the sake of illustration. If it is the first time you checkout on this branch, git will ask you to name the local branch: we recommend to leave it as is. - ⚠ Now that you have the branch locally, add it ASAP to your own
originremote repository: push that branch ONLY tooriginremote withupstreamenabled:- Go to the git graph
- You can see your new branch here, right-click on it and select
Push Branch...- 💡 Right clicking on the Git Graph interface opens different options depending on where you click! Right click on the local branch to get local branch options, right-click a remote branch to open remote branch options and finally, right-click the commit (anywhere else on the line, for instance on the commit description) to open commit options.
- Confirm that the remote on which the branch will be pushed is the one of your group,
origin; if it is thereferenceorigin, unselect it and select your remote. Confirm that the check boxSet Upstreamis well checked in order for this local branch to correctly trackoriginrather thanreference: - Click on
Yes, push - Doing this is important to avoid having two different branches on your remote from the two group members.
This example shows the steps for TP2_Exercise but those will be the same for TPx_Exercise, TPx_Solution or any other branch that you can fetch from reference GitHub repository.
Comparing your code with the solution
You can compare your code with the one in the solution through VSCode's compare tool.
- In the Source Control tab, click on the
View Git Graphbutton; - Hold
Ctrl(Windows) orCmd(UNIX) key and click on the 2 branches to be compared. ⚠ You must select the commit title, on the right hand-side of the branch's box;- e.g: TP1_Solution with TP1_Exercise
- A list of files that are different across the 2 commits are generated;
- You can open and see the differences between any of these files just by clicking on them;
- Below is what you might see when checking the differences in the main.c file.