How To Fix Common Github Branching Issues Without Any Code

Kyle Law
3 min readFeb 6, 2020

--

Github is the industry-standard for version control where you can show off your best code and reposit your projects. In a proper GitHub workflow, the master branch is a precious, sacred branch which should only contain clean, working code. In practice, code progress can only be merged into the master branch after being approved by a code reviewer or senior developer. After reading this article, you’ll be able to fix common issues that may arise during the GitHub workflow without any code like git reset or git push --force .

Fix GitHub Issues Without Any Code?!

Before stepping into the cases, here are some functionality that can be performed on the GitHub platform itself:

Your sub-branches can be deleted (Your Repo > Branches > Delete Icon), whereas the master branch can’t.

Delete Branches on GitHub

Your sub-branches can be set as the default(master) branch (Your Repo > Setting > Branches > Default branch). Literally, on GitHub, the master branch is a sub-branch named ‘master’ being set as the default branch.

Set Default Branch on GitHub

You can branch from previous commits. (Your Repo > Commits > Click on the specific commit you want to branch from > Browse Files > Branch it from that commit)

Branching from Previous Commits

Alright, let’s dive into common issues on the Github workflow.

Issue 1: Committed directly to the master branch without creating feature sub-branches. (As the master branch is a precious, sacred …)

Solution:

  1. Create a branch named ‘feature-branch’ from the master with the latest commit.
  2. Set ‘feature-branch’ as the default branch(‘master’ becomes a sub-branch).
  3. Delete the ‘master’ sub-branch.
  4. Create a sub-branch named ‘master’ from your first commit of ‘feature-branch’.
  5. Set the ‘master’ sub-branch as the default branch.
  6. Tada! Your master branch is currently on the first commit whereas ‘feature-branch’ contains full commits.

Issue 2: Accidentally pushed to master branch instead of feature-branch. (This happens when you git push without specifying the branch name)

Solution:

  1. Push the progress to feature-branch as well to ensure both are at the same commit
  2. Perform steps 2 & 3 above to delete the master trunk.
  3. Create a sub-branch from the previous commit and named it as ‘master’.
  4. Set the ‘master’ sub-branch as the default branch.
  5. Tada! Your master branch is with the previous commit, whereas your feature-branch maintains the full progress.

Issue 3: Accidentally merged feature-branch into the master branch without approval from code reviewers.

Solution:

Similar to the first solution. Change the master branch as sub-branch and delete it, create a sub-branch named ‘master’ from previous specific commit, set it as the default branch, then pull a new request to code reviewers again.

Issue 4: The master branch and feature-branch are entirely parallel. (This happens when you improperly force push or force reset the master branch from your local terminal)

Solution:

Delete the master branch by setting feature-branch as default, create a sub-branch named ‘master’ from the previous commit, then set it as the default branch.

The above summarized the common issues that could happen during the GitHub workflow. Although it provides an easy way to solve them, it is recommended to fully understand the GitHub workflow and avoid these mistakes as much as possible. If you face any issues regarding the GitHub workflow that aren’t being covered in this article, feel free to reach me out on LinkedIn and I’ll be pleased to figure that out with you :)

This article is written by Kyle Law, a full-time Microverse student, as being part of the professional curriculum. Microverse full-time software development program provides beyond technical skills, but also the necessary professional skills required as a software developer. To find out more, please visit www.microverse.org.

--

--

Kyle Law

Software Engineer - Writing about Cloud & DevSecOps