Getting started with Git Workflow

Hellen Kokach
IAN Engineering
Published in
7 min readMay 13, 2021

--

The Impact Africa Network Engineering team had a knowledge-sharing session where we learned about Git workflows.

Over a period of 12 months or so, we have built a remote team of engineers who are passionate about building great quality products. We endeavor to translate all the cool stuff we learn into something you too can benefit from.

Today, we explore Git workflows.

Here are some of my key takeaways and also a demo tutorial on how to get started. Enjoy!

Introduction

First of all, let’s start by learning the importance of using Git workflows in our projects. Git workflows enable one to use Git to accomplish work in a consistent manner. When working in a small or large team on a project, it is important to ensure your work is consistent and up to date. Git offers a lot of flexibility in how users manage changes in their projects.

Intended audience: Who the article is for

  • Developers who plan on project collaboration

Requirements

  • A laptop
  • Github account
  • Code editor e.g Visual Studio Code
  • Command Line Terminal e.g git bash or your local computers CMD

What we will cover in the article

In this article we will cover the following:

  1. Creating and Cloning a git repository
  2. Creating an issue
  3. Creating and merging a pull request

Section 1: Creating and Cloning a git repository

Now onto the fun part, we shall create and clone an existing repository and modify files in it.

Step 1: Creating a git repository

  1. Login to your GitHub account.
  2. To create a new repository click on the new button on the left side tab or the plus icon in the upper right corner of the screen and click New repository.
Create New Repository
Create New repository (second option)

3. On the create repository page you will write the name of your repository. It’s best to keep the name short and memorable. You can also add a description of the repository but this is not mandatory.

4. Choose repository visibility whether you want it to be private or public and initialize the repository with a README file by checking the box ‘Add a README file’.

5. Click the Create repository button

Steps to create a new repository

Step 2: Cloning a repository

  1. Once you have created a repository navigate to the main page and above the list of files click on the Code button. In this tutorial, we will clone the repo using HTTPS so copy the URL.
  2. Create a folder on your computer where you will clone the repository. Navigate to it in your terminal and clone the repo using this command.
git clone <paste url here>

3. Once the repo has been cloned, navigate to the folder inside it that has the README file in the repository. The name of the folder will be the same name as the repo. In this tutorial, the name of the repo is called ‘Done-test-platform’.

Terminal window

4. You’re almost done with the first step but before we move on to the next section, let’s talk about branches. Branches represent an independent line of development. The main/master branch is the default one where all the changes get merged back into.

Image source: nobledesktop.com

It contains the production code that the user will interact with hence it is advised to never ever push code that is not tested to it otherwise you are going to receive lots of unhappy calls.

Instead, it is good practice to create a develop branch that can stand in for the main branch during development. The technical/team lead can then merge the develop branch with the master branch once the development is completed and everything is well tested.

git checkout -b <branch name>

Note: Replace <branch name> with the actual name of your branch

The command above creates a new branch called ‘develop’ and switches to it. Use the command git branch to see which branch you are currently in.

Congratulations, You have created your first repo! We will move on to creating an issue.

Section 2: Creating an issue

Github Issues are a great way to keep track of who is responsible for a certain task. For example, let’s say you are working with a team of developers and you need a signup page. You can create an issue and assign it to one of the developers who will then work on developing the signup page. Once he or she is done with the task you can close the issue. Let us now see it step by step.

  1. Create an Issue by clicking on Issues on the tab and clicking on the New Issue button.
Issue tab
Issue button

2. If your repository uses issue templates, click Get started next to the type of issue you’d like to open.

If the type of issue you’d like to open isn’t included in the available options click Open a blank issue.

3. Give your Issue a title and a short description.

On the right-hand side tab, you can assign the issue to someone (including yourself) or multiple people in a team. You can also apply labels to classify and manage your issues. Click here to read more about labels.

Github Issue labels

4. Click Submit new issue button

I have created an issue called add signup page and assigned it to myself.

Created add signup page issue

You have successfully created an issue!

Section 3: Creating and merging a pull request

  1. For our last step, we are going to add a new file and create a pull request. To do this we need to create a branch called ft-signup where we will perform the operation.
git checkout -b ft-signup

The above command creates and switches to a new feature branch called ft-signup.

2. Once the branch is created, you can create a new file called signup.html.

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8">
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0">
<title>Sign Up</title>
</head>
<body>
<p> A demo page that allows users to sign up</p>
</body>
</html>

3. Commit (save) your changes using the following commands.

git add .git commit -m "This commit will create a signup page"

N/B It is good practice to follow the Git naming conventions to ensure consistency

4. Push your changes

git push — set-upstream origin <branchname>

Let us now create the pull request

5. Once you have pushed your changes will see a notification on your Github page prompting you to Compare and Create a pull request. Alternatively, you can click the New Pull Request button.

Create pull request

You can add a comment and assign a reviewer to review your pull request before it is merged with the base branch.

Open a pull request

Once this is done (and the request is approved if you had assigned a reviewer), you can merge the pull request with the base branch which in this case is the develop branch.

Merge pull request

Important Tip: Always remember to pull changes from the main/develop branch (using the command git pull) whenever you know a change has been made to ensure you have the latest changes in your project and avoid merge conflicts.

--

--