A basic Git workflow in theory and practice

Description

This session we will cover the following topics:

  • The basic concepts behind Git
  • A simple Git workflow for you individual projects
  • Publishing projects on GitHub

In the next session, I will talk about a collaborative workflow using Git and GitHub.

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 commited 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 🧑‍🍳 (15 min)

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

Now initialize the repository.

Open your project in the explorer

Go to Repository -> Show in Explorer to open your project in the 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 and open a text file (file ending .txt) 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.

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.

For the fast ones:

  • Make a change to your first recipe and commit this change
  • Add another recipe and commit it to your repository
  • Add and commit some other file formats (e.g. a png picture of your dish, a pdf file, …)

Publish your project on GitHub (10 min)

Publish your cook book project on GitHub (Publish button on the top right). In the dialogue that opens, chose to make your project public (easier for the collaboration session tomorrow).

Check out your brand-new GitHub repository

Check out how your repository on GitHub looks like. You can find it via Repository -> View on GitHub or by logging into your GitHub account in the browser.

Have a brief look around in your GitHub repository. Which buttons are there? How do your files look like?

For the fast ones

Switch back to your local repo and change some more things. Always commit and push your changes to GitHub and check out how they look online.

Some ideas:

  • Work on the README file and add some information about your cook book project there.
  • Add or change recipes.

Undo changes in your repository (5 min)

If you only have 1 commit in your project, make 1-2 other ones (e.g. add a recipe or change something).

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

Choose a commit that you want to revert. Select the commit and right-click to revert it. See how your history has changed.

Checkout a previous commit

To see your cook book at an earlier stage, select the commit you want to jump back to. Then right-click and checkout this commit.

You will get a warning that you will create a detached HEAD state. This is ok, so checkout anyways.

See how your history changed. GitHub desktop will tell you that you are now in Detached HEAD mode. If you now look at your cook book files, you will see that they correspond to an earlier version.

Note

You cannot work on the project in this state. You can only look at the files.

To come back to the current state, click on the current branch button at the top and select the main branch again

Ignore files

We only want actual recipe files in our project. All other files should be ignored.

Add a .gitignore file

Find a random file on your computer and copy it into your cook book project.

Check if GitHub Desktop recognized the change to your repository, but DO NOT COMMIT this file.

This file does not belong to your cook book, so it should be ignored by Git.

You can ignore the file with a right click and select Ignore file.

This will add the file to the .gitignore file.

Then check the Changes view of GitHub Desktop. What is different now?

Have a look at the newly created .gitignore file. You can just commit and push it like any other file.