git branch workflow: 7 easy steps (video)
Last Updated on Nov 27, 2022
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
Second Step
Then, run the command
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
And then go to it with
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
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
Or if there is an issue I would name it
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
Sixth Step
And now you can merge your branch with the master branch by running this command
* 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
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
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:
- Git checkout master
- Git status
- Git checkout -b branch-name
- Code & Commit
- Git checkout master
- Git merge branch-name
- 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.
Link to Video:
You can watch the original video on youtube.