2 minute read

How to use a feature branching workflow in Github.

Overview

This Git Hub pages site was set up thanks to Chad Balwin’s Building a Free Blog with GitHub Pages in Minutes (14 March 2021) instructions and template.

After publishing the first post, the question was then how to make it more sophisticated by working in Visual Studio Code and using a branching strategy so that each post is a feature branch.

We could visualise this with Mermaid , if it worked :

graph:

       commit
       commit
       branch develop
       commit
       commit
       commit
       checkout main
       commit
       commit 

The first step was easy as source control in VS Code had a big Clone button. How to do branching?

Atlassian’s Bitbucket tutorial on Git Feature Branch Workflow

Start up

Start by checking out the main branch (Atlassian):

git checkout main
git fetch origin 
git reset --hard origin/main

New branch

As this was a brand-new project I had to adapt the instructions to create a develop branch:

git checkout -b develop 
git push -u origin develop

So far so good, but having adapted the instructions, there was now a question of how to create a feature branch off the develop branch.

New feature branch

The answer was quite straightforward thanks to Renat Galyamov’s How to create a branch from develop branch in Git.

git checkout -b post2 develop 

The remote returns a message on how to create a pull request for post2.

pseudocode:

cd "_posts" 
git add "2099-12-31_post2" 
git commit -m "getting started initial commit" 
git push --set-upstream origin post2 

Great! Now we have an error message from the remote saying “Your push would publish a private email address”.

Email privacy settings

We can resolve this thanks to Bryan Jimin Son’s How to resolve a GitHub error “push declined due to email privacy restrictions” when you try to push a change.

git config --global user.email <some number>+<your username>@users.noreply.github.com 
git commit --amend --reset-author

Second time lucky: pseudocode:

cd "_posts" 
git add "2099-12-31_post2" 
git commit -m "getting started initial commit" 
git push --set-upstream origin post2 

After publishing the post we will have to start a pull request in the browser to get the commandline instructions:

git pull origin develop
git checkout develop
git merge post2
git push -u origin develop

Tagging

Before we close out the feature branch it might be helpful to tag it in case we need to find something again.

Atlassian documents gis tag.

An annotated tag can carry a message that might prove useful in the future:

git tag -a p2 -m "Post number two"

Cleanup

When we’re done with the feature branch we may want to clean it out.

Free Code Camp describes How to Delete a Git Branch Both Locally and Remotely.

git branch -d post2 
git push origin --delete post2

QED

Categories:

Updated: