DEV Community

Drew Pellum
Drew Pellum

Posted on

The importance of using Git correctly and how to use it.

Yeah, we know you can store your code in Github, but what are the other benefits?

The primary benefit of GitHub is its version control system, which allows for seamless collaboration without compromising the integrity of the original project.

What does this mean?

Git allows you to create new branches of code to work on without updating the main branch.

This is cool, but why is that important?

  1. Bugs

When pushing only to the main branch, you can have typos in your code. This can break the code that is already working. Not ideal buddy.

  1. Updating Code

Yeah, it's cool to have code that always works, but if it never updates, then it will get left behind. Each day is an opportunity to learn what best practices in the industry are and you can make improvements to your code.

Technology is ever evolving and it becomes more advanced each day. Without updating your code, you don't give yourself the opportunity to use this new technology.

  1. Customers

In the tech world, there is always a way to improve a product. Customers give feedback on how they use your product and how they would like to use it in the future. Product managers take the feedback and prioritize features to start working on. It allows us to make our code more valuable and potentially increase profit in the future. By adding these features, customers are more willing to recommend your product to others increasing profit even more.

Now that you know why git is important and how it allows you to control your versions, how do you use it?

Creating a new branch in the terminal

  1. git branch

This allows you to see the current branch you are using.

  1. git branch <new-branch-name>

This will create a new branch off of the one you are currently using.

  1. git checkout <branch-name>

This allows you to checkout the new branch you created.

You can also switch branches using git switch <branch-name>

Now that you've created a new branch, you can start adding new code or update code that you've already written.

With that being said, make sure that you are git committing your new code with messages.

git add .
git commit -m "Message Here
git push

After you've pushed to your new branch, you can merge to the main branch. Make sure that it is working code FIRST.

You can merge to main by making a pull request. On your github page you can select pull-request and make a new pull request by following the steps in the gif below.

Pull Request from Git

Go to Pull Request Page

Create Pull Request

After doing this, you can merge the pull request into your main branch for production.

Now that you've merged into main what do you do with the code in visual studio?

You can pull!

Switch to main by git switch main


git pull

Now you have the active code in main branch and you can start the process all over again.

Following this guide will allow you to reduce mistakes that will create outages and bugs. It will also teach you important skills for a job. Many job postings require knowledge of git and it is important for them to have developers that won't cause setbacks or outages. They want to know that you will be able to help them with their main goal of delivering high quality products to their customers as fast as possible.

Top comments (0)