Exercises
Session 2: Basics of the Command Line
Create files and folders
- Within your chosen folder, create a new subfolder called
recipes. - Navigate into the
recipesfolder. - Create a new text file called
recipes.txt. - Confirm that the file was created by listing the contents of the folder.
- Add the title “My Favorite Recipes” to
recipes.txt. Which command or method did you use?
🚀 Bonus exercises
Writing and opening files
Add a first recipe to recipes.txt. Include at least a title and a short list of ingredients. Which command or method did you use?
Creating multiple files
Go back to your main course-related folder. Using the command line, create three new files: notes.txt, assignments.txt, and schedule.txt. Provide the command you used.
Wildcards
Use a wildcard pattern to list all .txt files in your folder. Which command did you use?
Combining commands
Imagine, that you are in a folder containing multiple text files with various extensions, including .txt, .md, and .docx. You want to move all the .txt files to a subfolder named text_files while keeping the other file types in the current directory. Write a series of command-line commands to accomplish this task, including creating the text_files subdirectory. Explain each step in your solution.
Setup & Configuration of Git: Setup & Configuration of Git
Configure Git
- If needed, navigate into the project folder using the command line.
- Set your Git username.
- Set your Git email address. This email address will appear in your Git history, so use an address you are comfortable sharing.
- Change the default name of the initial branch to
main. - 🚀 Optional: Change your default text editor.
- List the Git configuration settings.
Session 4: First steps with Git & Git Essentials
Initialize a Git repository
- If needed, navigate to the project folder using the command line.
- Initialize a new Git repository in the project folder.
Add content and commit changes
- Open
recipes.txt(created in the command-line session) in a text editor. - Add a short recipe entry (a title and a short list of ingredients — use any favorite or an intriguing AI-generated one).
- Stage the file.
- Commit the changes with a descriptive commit message.
🚀 Optional: Commit at least three additional recipe entries in recipes.txt.
Amend a commit
- If needed, navigate to the project repository using the command line.
- Add a new recipe to
recipes.txtwithout a title, and commit the change. - Now add a title to the recipe.
- Stage the change.
- Amend the previous commit to include the title change (without altering the commit message).
- Check the commit history to verify that the last commit message has not changed.
Create a .gitignore file
- If needed, navigate to the project repository using the command line.
- Add a file to your repository that you want to ignore, for example an image file like
image.jpg. - Check the state of your repository to confirm that Git noticed the added file.
- Create a
.gitignorefile. - Add a pattern to the
.gitignorefile to ignore the file. - Check the state of your repository again to confirm that Git now ignores the added file.
- Stage the changes in your repository.
- Commit the
.gitignorefile using a descriptive commit message. - 🚀 All macOS users: Also let your repository ignore
.DS_Store.
Session 5: Branches
Branches
- If needed, navigate to the project repository using the command line.
- Create a new branch with a descriptive name, e.g.,
add-pizza-recipe. - Switch to the new branch.
- Add a new recipe to
recipes.txt. - Stage and commit the changes to
recipes.txton the new branch. - View the contents of
recipes.txtto verify your changes. - Switch back to the default branch (
mainormaster). - View the contents of
recipes.txtagain to confirm that the changes do not exist on the default branch. - Merge the new branch into your default branch.
- Delete the feature branch.
- View the contents of
recipes.txtyet again to confirm that the changes have been merged into the default branch.
🚀 Bonus exercises
Create and resolve a merge conflict
- Deliberately create a merge conflict by making conflicting changes to the same section of
recipes.txton two separate branches (for example, change the same ingredient differently on each branch) and attempting to merge them. An example can be found in the branches chapter. - Resolve the merge conflict.
- Delete the merged branch afterwards.
Session 6: Integration with GitHub / GitLab
Connect to remote repositories using SSH
- Generate an SSH key.
- Copy the SSH key to your clipboard.
- Add the SSH key to the remote repository (for example, GitHub or GitLab).
Upload your local repository to a remote repository
- Create an empty repository on the remote repository hosting platform, for example GitHub or GitLab. Make sure to not initialize the repository with any files!
- If needed, navigate to your project repository using the command line.
- Set the remote URL of your local repository to your remote repository.
- Push the changes on your default branch (
mainormaster) to your remote repository.
Private collaboration on default branch (main or master)
- Add your exercise partner as a collaborator to your
recipesrepository on GitHub. - Clone your partner’s repository.
- Add a new recipe to your collaborator’s
recipes.txt(if you are unsure where to add it, ask your collaborator!). - Add and commit the changes.
- Push the changes to the remote repository.
- Pull your partner’s changes into your repository.
Private collaboration with pull requests (using GitHub Flow)
- If not done already, add your exercise partner as a collaborator to your
recipesrepository on GitHub. - Clone your partner’s repository (if not already cloned).
- Create a new branch in your collaborator’s repository.
- Add a new recipe to your collaborator’s
recipes.txt(if you are unsure where to add it, ask your collaborator!). - Add and commit the changes.
- Push the changes on the new branch to the remote repository.
- Create a Pull Request (on GitLab: Merge Request).
- Review the Pull Request that your collaborator made in your repository.
- 🚀 Optional: Add additional changes on the branch pushed by your collaborator.
- Merge the pull request into your repository.
🚀 Bonus exercises
Clone and sync your repository
- Move to a location on your computer where you want to clone a repository.
- Clone your remote repository to a different location on your computer.
- Create a new branch and add a recipe to
recipes.txtin the cloned repository. - Commit the changes and push them to GitHub.
- Pull the changes into the repository at the original location.
- Delete your newly cloned repository.
Add a README.md
- Find the option to create a new file on your remote repository in the browser.
- Name the file
README.md, add a brief description of your recipes repository (e.g., what kind of recipes it contains and who it belongs to), and provide a commit message. - 🚀 Optional: Play around with Markdown syntax.
- Save the
README.mdfile to the repository. - Pull the changes to your local repository.
Session 7: Collaboration on GitHub / GitLab
“Public” collaboration with pull requests (using a fork and GitHub Flow)
- Find out what forking is.
- Fork the project repository of the course instructor or another course participant (ideally, someone who is not your collaborator from the previous exercise). If you can’t find a suitable partner’s repository, fork Lennart’s
recipesrepository as a fallback. - Create an Issue in your new collaborator’s repository, indicating a recipe that you think is still missing.
- Repeat the steps from the exercise on collaboration with remote repositories using the forked repository:
- Clone the forked repository to a sensible location on your computer.
- If available, read the contributing guide of the repository before making any changes.
- Create a new branch and make one or multiple commits adding the recipe that you suggested in the Issue.
- Push your changes to the remote repository.
- Create a pull/merge request with your changes (hint: from the forked to the original repository) and refer to the Issue in your pull/merge request.
Find out about the contributing guidelines in Lennart’s repo and follow them when creating a new recipe.
Reviewing pull requests
- View any pull requests that are created in your
recipesrepository. - Review the changes made by the contributor in the pull request. Check that the contributed recipe follows the format of existing recipes and any contributing guidelines.
- If needed, discuss additional changes with the contributor in the pull request.
- Close the pull request by merging the proposed changes.