Skip to main content

A Git workflow for individual projects

Description

In this session we will cover the following topics:

  • What is Git and what are the basic concepts?
  • A simple Git workflow for your individual projects
    • Tracking changes
    • Undoing changes
    • Ignoring files
  • Publishing projects on GitHub

In the next session, you will learn a collaborative workflow using Git and GitHub.

Slides

Slides in full screen     Download PDF slides

Tasks

Create your own Git cook book 🧑‍🍳

All recipes will be simple text files and changes will be committed to the repository.

The goal is to give you a first idea and feeling for the basic Git workflow.

If you are stuck in a task, you can have a look at the How-To description of the Git workflow with detailed explanations and screenshots of all steps.

Create your own Git cook book 🧑‍🍳

Create a new repository

Open GitHub Desktop and create a new repository (File -> New repository) for your cook book project.

In the dialogue box that opens:

  • Give it the following name: cookBook-yourName (replacing yourName with your name)
    • This name is needed for tomorrow when we collaborate
  • Select where on your machine you want the cook book to be stored
  • Check the box to initialize with a README file

Click Create repository.

Open your project in the file explorer

Go to Repository -> Show in Explorer (macOS: Show in Finder) to open your project in the file explorer.

Do you see the hidden .git folder in there?

If you don’t see it you probably have to unhide hidden files.

In the Windows explorer, go to View and then check the Hidden items checkbox:

In the Mac finder, hit Command + Shift + . (the period key) at the same time. This is the keyboard shortcut to hide and unhide files and folders.

Add your favorite recipe

Create a text file (file ending .txt) in your cook book folder and open it in a text editor. Then add a recipe to the file. To speed things up, you can choose one from below and copy paste it into your file.

NoteUse a plain-text editor

Any plain-text editor works, e.g. Notepad (Windows), TextEdit (macOS) or VS Code.

  • macOS: TextEdit saves formatted text by default. Before saving, choose Format -> Make Plain Text.
  • Windows: File endings are hidden by default, so a file you name recipe.txt might actually be called recipe.txt.txt. To see file endings, check File name extensions in the Explorer (in the same place as Hidden items above).
Ingredients:

2 ripe bananas
2 large eggs
120 g all-purpose flour
240 ml milk
1 tsp baking powder
1 tsp vanilla extract
1 tbsp sugar
Pinch of salt
Butter or oil for cooking

Preparation:

Mash bananas and mix with eggs, milk, and vanilla.
Combine flour, baking powder, sugar, and salt.
Mix dry ingredients into wet ingredients until smooth.
Cook on a heated pan with butter or oil until golden brown.
Ingredients:

200 g ramen noodles
1 liter chicken broth
2 cloves garlic, minced
1 tbsp ginger, minced
2 tbsp soy sauce
1 tbsp miso paste
2 large eggs
100 g mushrooms, sliced
1 carrot, julienned
100 g spinach
2 green onions, sliced
1 tbsp sesame oil
Salt and pepper to taste

Preparation:

Cook ramen noodles according to package instructions, drain and set aside.
In a pot, heat sesame oil and sauté garlic and ginger until fragrant.
Add chicken broth, soy sauce, and miso paste, and bring to a simmer.
Add mushrooms and carrot, cook until tender.
In a separate pot, boil eggs for 7 minutes, then cool, peel, and halve.
Add spinach to the broth and cook until wilted.
Divide noodles into bowls, pour broth and vegetables over them.
Top with halved eggs and sliced green onions.
Season with salt and pepper to taste.
Ingredients:

240 g all-purpose flour
200 g grated carrots
300 g sugar
240 ml vegetable oil
4 large eggs
1 tsp baking powder
1 tsp baking soda
1 tsp ground cinnamon
0.5 tsp ground nutmeg
0.5 tsp salt
1 tsp vanilla extract

Preparation:

Beat eggs and sugar, add oil and vanilla.
Mix flour, baking powder, baking soda, cinnamon, nutmeg, and salt.
Combine wet and dry ingredients, fold in carrots.
Bake at 175°C for 35-40 minutes.
Ingredients:

450 g chicken breast, cubed
1 large onion, chopped
3 cloves garlic, minced
1 tbsp ginger, minced
400 ml coconut milk
400 g diced tomatoes
2 tbsp curry powder
1 tsp turmeric
1 tsp cumin
1 tsp coriander
Salt and pepper to taste
2 tbsp vegetable oil
Fresh cilantro for garnish

Preparation:

Sauté onion, garlic, and ginger in oil.
Add spices and chicken, cook until browned.
Add tomatoes and coconut milk, simmer until chicken is cooked.
Season with salt and pepper, garnish with cilantro.
Ingredients:

250 g all-purpose flour
150 g sugar
150 g brown sugar
225 g butter, softened
2 large eggs
1 tsp vanilla extract
1 tsp baking soda
0.5 tsp salt
300 g chocolate chips

Preparation:

Preheat oven to 175°C.
Cream together butter, sugar, and brown sugar.
Add eggs and vanilla, mix well.
Combine flour, baking soda, and salt.
Gradually add dry ingredients to wet ingredients.
Fold in chocolate chips.
Drop spoonfuls of dough onto a baking sheet.
Bake for 10-12 minutes until golden brown.
Ingredients:

200 g cherry tomatoes, halved
1 cucumber, diced
1 red onion, thinly sliced
1 green bell pepper, diced
100 g feta cheese, crumbled
50 g black olives
2 tbsp olive oil
1 tbsp red wine vinegar
1 tsp dried oregano
Salt and pepper to taste

Preparation:

Combine tomatoes, cucumber, onion, bell pepper, feta, and olives in a bowl.
Whisk together olive oil, vinegar, oregano, salt, and pepper.
Pour dressing over salad and toss to combine.
Serve immediately.

Commit your changes

Switch back to GitHub Desktop and have a look at the interface. Do you see your changes? Now commit your recipe file. Enter a commit message and a description and then click the commit button.

Optional tasks (if you finish early)

You can do these in any order — or skip them and just take a break.

  • Add other recipes and commit them to your repository
  • Make changes to existing recipes and commit them
  • Add and commit some other file formats (e.g. a png picture of your dish, a pdf file, …)
    • What do these files look like in GitHub Desktop?

Publish your project on GitHub

Publish your cook book project on GitHub: Click Publish repository on the top right. In the dialogue that opens, uncheck Keep this code private (easier for the collaboration session tomorrow).

Check out your brand-new GitHub repository

You can find your repository via Repository -> View on GitHub or by logging into your GitHub account in the browser.

Have a brief look around. Which buttons are there? What do your files look like? Can you find your README? How is it displayed?

Enter your repository in the spreadsheet

Tomorrow you will work in pairs on the cook book of your team mate.

Find your name in the teams spreadsheet and enter your GitHub user name and the link to your repository (copy it from your browser’s address bar).

Optional tasks (if you finish early)

You can do these in any order — or skip them and just take a break.

Work on your README

Switch back to your local repo and work on the readme. Then commit and push the results and check the changes on GitHub.

Tell people what your cook book is about in your README.md file. Use GitHub’s Markdown guide to look up the syntax.

Some things to try:

  • Add a heading and a short description with some bold text
  • Add a list of your recipes
  • Link to one of your recipe files, e.g. [Banana pancakes](banana_pancakes.txt)
  • A bit tricky: Add a picture of a dish, e.g. ![Banana pancakes](banana_pancakes.png). You need to add the image to your repository first.

Add or change recipes

Switch back to your local repo and change more files. You can e.g. add or change recipes. Then commit and push the results and check the changes on GitHub.

Undo uncommitted changes

Make some changes to an existing recipe file, but do not commit them. See how GitHub Desktop recognizes these changes. Now, right-click on the changed file and select Discard changes.

Revert a commit

If you only have one recipe, add another one and commit it first.

Now, have a brief look at the history of your repository in GitHub Desktop.

In the History tab, right-click your most recent commit and select Revert changes in commit. What happened to your history?

Ignore files

Sometimes there are files in your project folder that should not end up in your repository (e.g. large data files, personal notes, temporary files).

Add a file you don’t want to track

Copy any file from your computer (e.g. a PDF or an Excel file) into your cook book folder.

Switch to GitHub Desktop. Do you see the new file in the Changes tab? Don’t commit it!

Ignore the file

Right-click the file in the Changes tab and select Ignore file.

What changed in the Changes tab? Which file appeared instead?

Commit the .gitignore file

Open the .gitignore file in a text editor. What’s inside?

Commit and push the .gitignore file.

Optional tasks (if you finish early)

  • Copy two more files of the same type (e.g. two PDFs) into your folder. Right-click one and select Ignore all .pdf files. How does the .gitignore change?

Prepare for the collaboration tomorrow

Tomorrow you will work on the cook book of your team mate. For this, you need access to each other’s repositories on GitHub.

Invite your team mate

Find the GitHub user name of your team mate in the teams spreadsheet.

Open your cook book repository on GitHub (in GitHub Desktop: Repository -> View on GitHub).

Go to the Settings tab of your repository (not the settings of your GitHub account) and select Collaborators -> Add people.

Note

GitHub might ask you to confirm your password or enter a 2FA code. This is normal.

Search for the GitHub user name of your team mate and add them to your repository.

Accept the invitation of your team mate

You will get an email from GitHub with the invitation of your team mate. Open it and accept the invitation.

No email? Open the link to your team mate’s repository from the spreadsheet, add /invitations to the end of the address and accept the invitation there.

Let us know you are ready

In the spreadsheet, check the box I accepted my partner’s invitation.

Checkout a previous commit

You can jump back in time to see your cook book at an earlier stage.

Check out an earlier commit

In the History tab, right-click an older commit and select Checkout commit.

GitHub Desktop warns you that this puts you in a detached HEAD state. That’s ok, so check it out anyway.

Look around

  • What does the Current branch button at the top say now?
  • Open your cook book folder. Which recipes are there? Do they match the commit you checked out?
Note

In detached HEAD state, only look at the files. Don’t make changes here.

Go back to the present

Click the Current branch button and select main.

Check your cook book folder: are all your recipes back?