Git basics: Branches and strategies

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
You're welcome! Thank you too. My git workflow could be better - the series is really helping
In this series we'll cover some basic, but very important topics in Git, GitHub and Open source
Pull requests are a vital part of using Git. In this article, we'll look at making a pull request for our repository. You should have a good understanding of how pull requests work and the steps needed to take. After this, we can look into creating p...
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Branches are an essential part of using Git. You can view a branch as separate versions of your project.
Generally speaking, it's a good thing always to have these two branches in place:
Besides these branches that are always there, you might encounter some other branches. These other branches depend on the type of issue they solve.
Your project is live, but you realized a typo or a minor styling issue. It's always something that needs to be solved right away.
These hotfix branches can be merged directly into the master branch; however, don't forget to merge them into development to keep up to date.
More often, you'll be making new features. This could be a small feature or a bigger feature that might take a while to create.
In either way, you'll be using multiple feature branches. Each feature should be as small as possible, so it narrows down what that branch does.
Once you are finished with a feature, it should be merged into the development branch for testing purposes.
The testing should always be done on the individual/development branches. Once the tests are good and happy with the results, you can merge development into master.
If you want to be super fancy, you can introduce release branches. (For me, that's not a super high need)
With this, we have something called a GitFlow.
This workflow created by Vincent Driessen describes the flow that should be taken when developing using Git.
This is an opinionated flow, but I've seen this success in a lot of different companies. Hence it's always the flow I choose for my projects.
See below for a visual representation of the model.

This might all sound cool to you, and you have a good understanding of committing code to Git. But we haven't used any branches other than the master branch till now.
Let's open up our project and create a development branch from whatever we have now.
git checkout -b development
This will create a new branch called development.
We can, however, also create a new branch of specific other branches.
git checkout -b feature_1 development
These branches will still be local and not pushed to GitHub.
To push a different branch, you can use the following command:
git push origin development
git push origin feature_1
And if we then go over to GitHub, we should see two new branches show up.

Just be aware of which branch you are working on.
You can always switch to another branch by using the checkout command.
git checkout master
This command will reset you to the master branch. You can use any branch name instead of master.
And that wraps up branches in Git. I hope you learned something about Gitflow and how to make your first own branch.
You can view my branches on GitHub.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter