Using a Git Workflow

A step-by-step breakdown of an effective Git workflow

Jordan Carroll
6 min readFeb 17, 2021

A Git workflow is a system that a development team uses to efficiently build projects in tandem. Workflows provide us with approaches we can use to share code with one and other in an organized manner. There are many different workflows, but the one described in this article is tried-and-true. The sequence below is inspired by Git workflows described by Michelle Rios and Sylwia Vargas, two phenomenal developers and programming instructors.

1. One teammate creates the repository on Github.

  • On GitHub, click the plus sign in the top right corner.
  • Click “New Repository” in the dropdown menu.
  • Type a name for the repository in the “Repository Name” field. Repository names are usually lowercase and descriptive of the project you will be working on. Each word in the name should be separated by a hyphen (e.g., semester-one-project).
  • Enter a description for the repository in the “Description” field. This step is optional.
  • Use the radio buttons to choose whether to make the repository Public or Private. Keep in mind that if your repository is public, anyone on the internet can see it, but you will still be able to choose who can edit it.
  • Use the checkboxes to “Add a README file,” “Add .gitignore,” and/or “Choose a license.”
  • “Add a README file” will automatically add a file to your repository that can be used to store a README. A README is a long description of your project that others can use to learn more about it. This is a very useful feature that most developers use, so most will check this checkbox.
  • “Add .gitignore” will add a template to your repository that will allow you to choose which files in your repository you do not want to track with GitHub and Git. This is a somewhat obscure feature that most beginner developers do not use, so most will not check this checkbox.
  • “Choose a license” will allow you to “license” your repository, meaning you will be able to legally specify what other users can and can’t do with your code. If you select a license and make your repository public, your code will be open source, meaning other users may use your code for free for whichever purposes your license allows. If you do not have a license, the default copyright laws apply, meaning no one may legally use your code for anything. Most developers choose the MIT License.
  • Click “Create repository”.

2. The teammate who created the repository adds the other members of their team as collaborators to the repository.

  • Click “Settings” near the top right corner.
  • Click “Manage access” on the left side of the screen.
  • Click “Invite a collaborator” toward the bottom of the screen.
  • In the field, type the GitHub username, full name, or email of someone you’d like to add as a collaborator. When their information appears, click on it then click “Add username to this repository”.

3. The teammate who created the repository adds a dev branch to the repository.

  • Navigate to the main page of the repository you’ve just created.
  • Click the branch selector menu near the middle left.
  • Type “dev” into the “Find or create a branch…” field.
  • Click “Create branch: dev from ‘main’” below.

4. Every member of the team clones the repo onto their computer.

  • Navigate to the main page of the repository you’ve just created. Click the green “Code” button.
  • Make sure “SSH” is selected then click the clipboard icon to the right of the field.
  • Open the terminal on your computer.
  • Use cd to navigate into the folder or file where you would like to save the newly created repo on your computer.
  • Once you have navigated to the desired location, type git clone, then make a space, then paste the SSH that you just copied. Hit enter.
  • Your repository should now be saved on your computer.
  • cd into the repository folder. Type code . then click enter to open the repository in your code editor.

5. Before each coding session, open the terminal within your code editor and enter the command git pull origin main to make sure that your main branch on your computer is up to date with the remote main branch on GitHub.

6. Next, enter the command git branch to double check which branch you are on. You almost never want to code on the main or dev branches when you’re writing new code, so if you are on one of these branches, create and switch to a new branch using step 7 below.

7. Enter the command git checkout -b branch-name-here to create a new branch and switch to that branch. A good naming convention for new branches is nameOfTheNewFeature-yourFirstName (e.g. addingLoginPage-jordan, modifyingCommentFeature-jordan, etc.)

8. As you’re coding, periodically push to this new branch using the commands below. Your commit message should be descriptive of the work you have done so far (e.g. git commit -m “modified the seed data”, git commit -m “updated the delete button”, etc.)

  • git add .
  • git commit -m “commit message here”
  • git push

9. Once you have completed the feature you were working on and you have checked that it has no bugs, merge it to the dev branch using the commands below:

  • git checkout dev
  • git merge branch-name-here

10. Next, your teammate(s) will check whether the code you merged to dev works well. If everyone decides to keep the code, your teammate(s) will merge dev to main using the commands below:

  • git checkout main
  • git merge dev

--

--