Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Git Tutorial 19 – Git Switch – Create and Switch Branches – An Alternative of Git Checkout

Posted on 04/23/2025 By admin

As a part of GIT Tutorials End To End, we will learn about the Git Switch command in this post.

I will expect that you are aware of the basic concepts and commands of GIT. But if you are a beginner in GIT then I strongly recommend you to refer GIT Basic Commands and Concepts section on my blog first.

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

Let’s clone one of my public repo to practice and learn easily. The same repo I have used in my previous posts. In this repo, I have only the default branch “main” and three commits.

Git switch is a new command introduced in Git version 2.23. It is mainly for creating and switching branches. It is an alternative to the Git Checkout command. We have already learnt to create and switch branches using the Git Checkout command here.

To create a new branch use git switch -c command.

Please note here that you will be switched to the new branch using the git switch command like git checkout.

We know by default a new branch will be created from what HEAD currently points to. In the above command, a new branch will be created from the main branch. But we can create a new branch from another branch as well.

We have created a new branch branchA. Let’s create a new commit in this branch.

Currently HEAD points to branchA with its latest commit.

If we create a new branch it will be created from branchA and will have three commits as shown above.

Branch main will still have only two commits as of now. If you want to create a branch from the main branch then you can use git switch -c command.

To switch to the existing branch use “git switch ” command. If you provide a non-existing branch name then it will give an error as “invalid reference“.

We can directly switch to a remote branch as well. If we pass the remote branch name then a local branch will be created with the same name for the first time and tracking information will be set up. I have created a remote branch using GitHub.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe to my YouTube channel.
#ThanksForReading
#HappyLearning

Uncategorized

Post navigation

Previous Post: Selenium Framework 4: Understand Linear Framework in Selenium
Next Post: findElement() And findElements() Methods in Selenium WebDriver

Related Posts

December 22, 2018 – Make Selenium Easy Uncategorized
Make Selenium Easy | Make Selenium Easy – Selenium Tutorials : End To End Uncategorized
image – Make Selenium Easy Uncategorized
January 2019 – Make Selenium Easy Uncategorized
Hierarchy of Selenium Classes and Interfaces – Make Selenium Easy Uncategorized
Java Programs 15: Java Program to Print Fibonacci Series at Given Position Using Recursion Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark