Chapter 4: The General pattern for using Git

A pattern or template for using Git in Day-to-Day life

Suryaa Jha
Suryaa Jha’s Blog
3 min readApr 26, 2021

--

Git’s Workflow

When you start using Git as a Version Control System(VCS) on your projects it seems like overhead. But as you advance your journey using Git, you will quickly notice that “using Git is a cakewalk”. The steps are almost identical to a pattern or a template. For example, the following are some patterns

  1. Edit some files, stage those changes and commit
  2. Checkout a version from Git’s Repository and work on it …

In this chapter, we will discuss the basic steps in which you can use Git. You can take this as a template or a pattern. I have divided these patterns into 3 basic tasks, each task uses those 3 special sections of Git we discussed in the earlier chapters Part1 and Part2.

As you can see in the above diagram, Git’s Workflow is divided into 3 tasks as explained below. We will also touch on what sub-tasks you do in these 3 Tasks.

Task #1: Prepare The Next Version

Here we enhance our project. Enhancing may include, adding a new feature or fixing a bug. In very simple terms you will be taking your project from one version to another better version. Following are the non-exhaustive list of sub-tasks you do to prepare the next version

  • Create a new file
  • Modify/Edit one or more files, editing can include…
    1. Addition of new code
    2. Removal of existing code
    3. Or the combination of both
  • Stage/Add the changes to the Staging Area from Working Directory i.e staging new modifications to one or more files.
  • Unstage/Remove the changes from Staging Area i.e to remove staged changes from the staging area.
  • Editing/Adding/Removing from Working Directory to Staging occurs one or more times as denoted in the above diagram as a loop.

Task #2: Review and Commit

Once you are done with the first task the staging area shows how your project is going to look in the next version. If you are happy with the “prepared next version” present in the Staging Area you commit(store) the next version permanently in your Git’s Repository(version database). To summarize, the following is the non-exhaustive list of sub-tasks you perform.

  • Review the next version
  • Compare the next version with the previous version stored in Git’s repository
  • If satisfied, commit or store the next version in Repository

Task #3: Checkout a previous version

Checkout is a process of bringing any version say ‘Version X’ of your project from Git’s Repository to the Working Directory. Checkout is done to enhance ‘Version X’ and create and store new ‘Version Y’ into Git’s Repository. If you are following my previous chapters you will know that we can’t bring a version directly from the Repository → Working Directory, it must happen through ‘Staging Area’ thus the Staging Area also stores the checked-out version i.e ‘Version X’. In short, the following is the non-exhaustive list of sub-tasks you perform.

  • Checkout any version from Repository → Staging Area → Working Directory
  • Then perform Task #1 on the checked-out version to create a new better version

By this time you should feel comfortable using Git. There are a lot of exciting features like Git Branching that we will discuss in the next chapters.

--

--

Suryaa Jha
Suryaa Jha’s Blog

Software Engineer → Fitness Freak → Writer → Reader → Spiritual → Experiencing my childhood