GitHub Branch and Git

Luis Castillo
2 min readJan 24, 2022

Github and Git are two powerful tools that every developer needs, and knowing how their work is essential to work on a project or in collaboration as a team. Today I want to show a few commands that every developer should know. I’m explaining these codes with the visual studio code editor.

Pull code from GitHub

When working on a project with multiple developers, this command is essential.

git pull origin main

This command will allow you to pull all the code updates from the main branch from Github. The recommendation is to run this command every time before doing any code. If you are working on a project with a team and another developer commits a code to the main branch, this command allows you to update all the code and files with the main branch.

Create new branch

The second command that you will be executing many times will allow you to create new branches so you can work on your code without affecting the main branch.

git checkout -b <branch name> 

Keep in mind that your Visual Studio will be working on the branch created when you run this command.

Switch branch

The above command will create a branch, but what about if I want to go to the main branch of any other branch. The following command will help you to move from branch to branch.

git checkout <name of the branch you want to switch>

Push branch to GitHub

When you are ready to send the part of your code to GitHub, it’s time to run the push command. To push your branch to GitHub, the following command will send your branch to Github without affecting the main branch.

git push origin <branch name>

When this command is executed, the branch will be ready for you to review the code. In this stage, if you are working with another developer or a manager, your manager will review the code you wrote. If any change needs to be made, the manager will write it in the comments area; if everything is fine, they will approve the code to go to the main branch.

Delete branch

Good practice to do is when you create a branch, and you are done working on that branch is common to Delete the branch you were working on. The following command will delete branches that you don’t need anymore.

git branch -D <name of branch>

There are more commands that you can use, but I think these are the ones you will interact with the most.

--

--