Skip to main content

A collaboration workflow with Git

Description

Apart from letting you track your changes over time in your individual projects, Git is also very powerful when it comes to collaboration with other people. In combination with a platform such as GitHub or Gitlab, you can seamlessly collaborate without losing the overview of your project.

This session will be about:

  • Cloning and pulling
  • Branching and merging with Git
  • A collaboration workflow with GitHub
  • Pull requests and code review

Check out the previous session if you missed it, where I talked about basic Git concepts and a simple Git workflow.

Slides

Slides in full screen     Download PDF slides

Tasks

The goal of these tasks is to get a feeling for a collaborative 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 the steps.

Clone the cook book repo of your team mate

Use GitHub Desktop to clone the cook book repository of your team mate.

Go to File -> Clone Repository.

In the tab “GitHub.com” you will find a list of all your repositories, including the ones where you are a collaborator. Find the repository of your team mate and clone it to a local path of your choice (not inside your own cook book folder).

CautionWhat if I don’t see the repository of my team mate?
  • Click the refresh button next to the search field. The list does not always update automatically.
  • Check that you accepted your team mate’s invitation (open the link to your team mate’s repo from the team spreadsheet and add /invitations to the end of the address). Without the invitation, you can clone the repo but you cannot push to it.

You can also clone with the URL of the repository. Open your team mate’s repo on GitHub (see the team spreadsheet), click the green Code button and copy the HTTPS address. In GitHub Desktop, switch to the “URL” tab and paste it there. Then clone it to a local path of your choice (not inside your own cook book folder).

Open your team mate’s cook book in the file explorer to see which files are already in there (Repository -> Show in Explorer, on macOS Show in Finder).

Try branching and merging

Make sure that you are in your team mate’s cook book (check which repository you are in on the top left).

Create a branch

Create a new branch to add a recipe (Branch -> New branch). Give it a short name that describes what you will do, e.g. add-ramen.

Check the top middle of GitHub Desktop: Your new branch should be the current branch.

Add a recipe

Now go to the project folder (Repository -> Show in Explorer, on macOS Show in Finder) and add a file for a new recipe.

You can again copy paste a recipe from below. Choose one that isn’t in there yet.

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 to your branch

Add and commit that new recipe to your branch.

Merge into main

Now switch back to the main branch (click on the “current branch” button on top and select “main”).

Merge your new branch into the main branch (Branch -> Merge into current branch -> select your branch). Now check the commit history to see if your branch commit is actually there.

Push main

Push main to GitHub (Push origin) to share your changes with your team mate.

Optional task (if you finish early)

You can do this or skip it and just take a break.

Switch back to your branch, change the recipe you added and commit. Then switch to main, merge your branch and push main to GitHub.

Make a pull request in your team mate’s repo

Make sure you are in your team mate’s repository (top left of GitHub Desktop).

Create another branch

Switch to main, then create another branch (Branch -> New branch). Make sure that you are on that branch (top middle of GitHub Desktop).

Make some changes

Open a file in your team mate’s cook book and make some changes. Save and close the file and switch to GitHub Desktop.

Now commit these changes.

Publish and push branch

Click Publish branch on the top right to push your branch to GitHub.

Create the pull request

Now open the repository on GitHub (Repository -> View on GitHub). On top you should already see the option to “Compare & pull request”:

Click on that button and use the dialogue window that opens to describe your changes. Then create the pull request by clicking on the green button that says “Create pull request”.

Optional task (if you finish early)

You can do this or skip it and just take a break.

Until the pull request is merged, it updates automatically with anything you push to your branch. To try this, make sure you are still on your branch in GitHub Desktop, make some more changes, then commit and push them.

Review and merge the pull request on your repo

Wait until we start this task together, so that everyone has a pull request to review.

Now it’s time to look at the pull request your team mate left in your repository and decide if you want to merge it or not.

You can see new pull requests by the number next to Pull requests at the top of your repo:

Open the pull request and click through the tabs, e.g. Files changed.

You can leave a comment or ask for changes if you want.

When you are happy, you can merge the pull request by clicking on the green “Merge pull request” button:

Now the changes are integrated into the main branch on GitHub.

Finally, switch to your own cook book repository in GitHub Desktop and pull the changes (Pull origin; if the button says Fetch origin, click that first). Have a look at the commit history to see what changed.