Loading

Quipoin Menu

Learn • Practice • Grow

git / Create and Switch Branches
tutorial

Create and Switch Branches

Now that you understand the concept of branches, let’s create and switch between them. This is how you start working on a new feature or bug fix without disturbing the main code.

Creating a New Branch

To create a branch, use:
git branch branch-name
For example, to create a branch called feature-login:
git branch feature-login
This creates the branch but does not switch to it. Your current branch remains unchanged.

Switching Branches

To switch to an existing branch, use:
git checkout branch-name
Or the newer, more intuitive command:
git switch branch-name

Create and Switch in One Command

To create a new branch and immediately switch to it:
git checkout -b branch-name
or
git switch -c branch-name

Working on a Branch

After switching, any commits you make will belong to that branch. For example:
git switch -c feature-login
echo "Login feature" > login.txt
git add login.txt
git commit -m "Add login feature"
Now the commit is only on feature-login, not on main.

Listing Branches

To see all branches and which one you’re on:
git branch
The current branch is highlighted with a *.


Two Minute Drill
  • git branch branch-name creates a new branch.
  • git switch branch-name switches to an existing branch.
  • git switch -c branch-name creates and switches in one step.
  • git branch lists all local branches.
  • Commits made on a branch stay on that branch until merged.

Need more clarification?

Drop us an email at career@quipoinfotech.com