KKAIROSافتح التطبيق
Practical guideTested1 min read

Create and switch to a new Git branch

Published:

Advertisement

What a branch is for

A branch is a separate line of work. You try an idea on it, and main stays untouched until you decide to merge.

git switch -c feature-x
git branch

Go back with git switch main. Delete a merged branch with git branch -d feature-x.

Common mistakes

Does git switch -c copy my files?

No. It makes a new pointer at your current commit and moves you to it. Your files stay as they are.

What is the difference between git switch and git checkout?

git switch only changes branches, so it is harder to misuse. git checkout also restores files and does more than one job.

Source: https://git-scm.com/docs/git-switch and https://git-scm.com/docs/git-branch

Full kit: Git Survival Kit