How to Switch in your Git Branch

Switch Branch in Git

Table of Content

  • Introduction

  • Changing Branch using Git checkout

  • Switching from one branch to the other

  • Conclusion

image.png

introduction

i have love to write about the problems i have been facing as a Web developer and the solution i got about it so that it will help other to solve the same problem whenever they are faced with it. particularly when Working on a project and you have others which are your team mate and you have to push your work to the Repo(which means Repository).

When working on a project, you are probably managing many different branches in your repository.

that is while you will always need to change your branch from either the Master or Main which ever way it is name, which will be very frequently.

In this tutorial, you are going to learn how you can change branches easily on Git.

image.png

Changing Branch using Git checkout

There are different git command that i believe by now you should familiar with like git add, git commit, git push, git pull, git merge, git checkout

The best and easiest way to switch or change your branch is using "git checkout" command and specify the name of the branch you want to change to and in a situation where the branch does not exist,

git checkout <existing branch> "git checkout main"
git checkout <new branch> "git checkout Sardius"

to check the particular branch you use the "git branch" command

git branch main "//if your branch is in main"

but you want to change or switch to the other branch, Now that you made sure that your branch exists, you can switch from the master branch to the “sardius” branch by executing the “git checkout” command.

git checkout sardius

image.png

Switching from one branch to the other

in a kind of situation, where you have complete your task and you have push it but there was a little correction that was told by your boss to make, then you will need to switch from the main branch or Master branch to the one you name your particular branch, lets check and see!!!

git checkout -b non-existing-branch

Switched to a new branch 'non-existing'

For example, let’s say that you want to switch to the “sardius” branch from the “main” branch.

in other to change from "git main" to "git sardius", then you will have to make use of the "git switch" with the function you want to check to

git switch sardius

image.png

Conclusion

Hope you enjoy it and now understand how to change your branch on GIt , Watch out for my next article very soon!!!! hope you learned something new..

Share with me your idea in the comment below about how this content has really helped you🤓🤓🤓

Did you find this article valuable?

Support Abidoye Oluwatobi's Blog by becoming a sponsor. Any amount is appreciated!

Â