LARA

Git instructions

Due to the grading infrastructure, we require all programming projects to be versioned in the same repository. In this document, we will present how to manage different projects in the same repository. We will showcase how to create a branch for each different assignment, switch between the different branches and send code from a branch to the server.

Disclaimer

Note that this is not a typical use of git. Ideally, all projects should have their own repository. This will not be the case here as our grading infrastructure requires all projects to live on the same repository.

Starting a new assignment

The first thing to do when starting any assignment (starting from assignment 2) is to create a new branch on your local repository. Open your terminal in your repository folder. Before doing anything else, save your work for the project you are working on and commit it to the repository. Then send it to the server.

> git commit -a -m "Your commit message here..."
> git push

Next thing is to create the branch for the assignment. You can give it any name you like. For instance, for assignment 2, you could give it the name reductions.

> git branch reductions

If you simply type `git branches`, it will show you all the existing branches and mark the current branch by a star.

> git branch
* master
  reductions

The master is the one that contains your project 1. The star indicates that we are still on this branch.

The command `git checkout` is used to switch between branches. Enter the following command now to switch to the branch you have just created.

> git checkout reductions
Switched to branch 'reductions'

The next step is to actually replace all files from the previous project by those provided in the exercise handout. Delete all files and folders from your repository folder (except the .git hidden folder). Do not worry, your code is still saved on the local repository as well as on the server. We will discuss later how you can recover all those files in a single command.

Now, take all the files from the handout and place them in the repository folder. The handout for each exercise can be found in the exercise description. Once this is done, commit all additions and removal of files to the repository by issuing the following commands, still in the repository folder:

> git add . -A
> git commit -m "Initial import of exercise X."

Now, we still need to inform the server of the new branch. To do so, issue the following command, where reductions is the name of the branch you want to push:

> git push --set-upstream origin reductions

From now on, you can simply send code to the server using the usual `git push` command.

Important note

Note that the `git push` command will only push commits made to the current branch to the server. If you want to push commits made to other branches, you will have first to switch to that branch and then issue the `git push` command. We will see how to switch between branches right now…

Switching between assignments

Since multiple assignments are live at the same time, you might want switch back to the branch of a different assignment. To do so, make sure that all your work on the current branch is saved and committed. Switching between branches is then as simple as:

> git checkout <the branch name>

For instance, to switch to the master branch, which holds assignment 1, issue the following command:

> git checkout master

If you have uncommitted changes before switching branches, the command may refuse to execute. You might see the following message:

Please, commit your changes or stash them before you can switch branches.
Aborting

In this case, either commit your changes to the repository using the `git commit` command, or stash them away using the following command:

> git stash

That's it!