Free cookie consent management tool by TermsFeed Generator git branch workflow: 7 easy steps (video) | Amir Kamizi
AMIR KAMIZI
Home Blog Courses Books Newsletter Store Membership Buy me a coffee
git branch workflow: 7 easy steps (video)

git branch workflow: 7 easy steps (video)

Last Updated on Nov 27, 2022

https://youtu.be/osNp79ew8f8

 

Transcription

Hello
This is amir
Today we are going to talk about git branching workflow
I will go through it step by step and help you understand the process

So let’s get started

First Step

The very first thing you should do is to make sure you are in the master branch. That way your new branch would be updated with all the latest changes in the master branch.
And in order to do that we need to run the command

git checkout master

Second Step

Then, run the command

git status

to make sure there is nothing to commit.

Third Step

Now it’s time to create a new branch. To do that we have 2 ways:

1- The first one is to create a branch and then checkout to it

git branch new-branch

And then go to it with

git checkout new-branch

2- The second way which is my favorite way is to combine the two mentioned commands. And we can achieve it by running this command

git checkout -b new-feature

The -b flag is telling git to create a new branch and then go to it

I’d like to add a side note about branch names. When you are working on a big project, sometimes it gets hard to track why a certain branch was created in the first place. I personally like to prefix the branches and give them a descriptive name. For example if we are adding a new feature for orders I would name it

feature-add-detail-to-order

Or if there is an issue I would name it

issue-with-the-sort-orders

Fourth Step

Ok as the 4th step, it’s time to do whatever you need to do.

Fifth Step

After you committed all your changes it’s time to go back and start the merging process.
And to do that you need to go to master branch first. So run the command

git checkout master

Sixth Step

And now you can merge your branch with the master branch by running this command

git merge feature-new-feature

* After this step there might be some merge conflicts. If there are then
Fix those and then run this command again.
Seventh Step

The last step is not necessary but it’s always a good idea to clean up afterwards.
In order to delete the branch that you’ve already merged run

git branch -d branch-name

The -d flag means delete the branch.
If you have not merged it already then git will show you a message saying that you haven’t merged it yet. It’s not possible to delete it.
Sometimes you really don’t want to merge it and you want to delete the branch. In that case you have to force the delete
You can do it by capitalizing the -d flag. And your command would be like this

git branch -D branch-name

And your done

Key Takeaways

Just a quick recap

We talked about 7 step git branching workflow to add a new feature or work on an issue
The steps were:

  1. Git checkout master
  2. Git status
  3. Git checkout -b branch-name
  4. Code & Commit
  5. Git checkout master
  6. Git merge branch-name
  7. Git branch -d branch-name

Final Words

and finally, if you liked what you learned please like and subscribe
That would be a great motivation to do more videos
If you have any suggestions or questions please leave a comment below and I try to answer them as soon as possible

That’s it
Have a wonderful day.

You can watch the original video on youtube.

Category: programming

Tags: #git

Join the Newsletter

Subscribe to get my latest content by email.

I won't send you spam. Unsubscribe at any time.

Related Posts

PHP random number
Feb 15, 2023 programming

PHP random number

Today we are going to talk about generating random numbers in PHP. Knowing how to generate a random number is more useful than you think. you can select random users and much more. ...

3 Min Read Read More
PHP Namespace
Mar 23, 2023 programming

PHP Namespace

Today we are going to talk about namespaces in PHP. Namespace is like putting the classes in a group. it helps you organize your code much better. It's a must-know topic for a PHP programmer. ...

7 Min Read Read More
PHP Exec
Mar 22, 2023 programming

PHP Exec

Today we are going to talk about exec in PHP. Did you know we can run system commands through PHP? Well not only it’s possible but also it’s very easy. You can do it with exec function ...

3 Min Read Read More
A Programmer's Guide to Debugging: Essential Steps to Follow
Mar 23, 2024 programming

A Programmer's Guide to Debugging: Essential Steps to Follow

Debugging is a crucial skill for any programmer, as it helps identify and fix issues in the code. Effective debugging not only improves the overall quality of your software but can also save you time and frustration. ...

10 Min Read Read More

Recommended Courses

Introduction to Machine Learning in PHP

Introduction to Machine Learning in PHP

Learn to Build Different Machine Learning Models Easily ...

PHP Tutorial Beginner to Advanced

PHP Tutorial Beginner to Advanced

Learn everything you need to start a successful career as a PHP developer ...