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

Learn how to contribute to open source projects in 7 easy steps (video)
Nov 27, 2022 programming

Learn how to contribute to open source projects in 7 easy steps (video)

we are going to talk about how to contribute to open source projects We will go through it together step by step ...

14 Min Read Read More
PHP Conditionals
Mar 21, 2023 programming

PHP Conditionals

Today we are going to learn about conditionals in PHP. Conditionals are very useful in any programming language. So important that we can argue that the foundation for all the technologies around us are conditions. ...

7 Min Read Read More
PHP array filter
Feb 14, 2023 programming

PHP array filter

Today we are going to talk about array filter in PHP. array filter is a very useful function and it helps you filter an array by key, value or both. ...

6 Min Read Read More
PHP Simple Tinker Like Script
Feb 15, 2023 programming

PHP Simple Tinker Like Script

Today we are going to build a simple Tinker in PHP. Tinker is a tool that allows users to interact with the application through the command line. ...

8 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 ...