GIT

Git Branch

Working with branches

Git Branch

Branches allow you to develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.

Create a Branch

To create a new branch:

git branch branch-name

Switch to a Branch

To switch to a branch:

git checkout branch-name

Or use the newer command:

git switch branch-name

Create and Switch in One Command

You can create and switch to a new branch in one command:

git checkout -b new-branch

Or:

git switch -c new-branch

List Branches

To see all branches:

git branch

To see remote branches:

git branch -r

Delete a Branch

To delete a branch:

git branch -d branch-name

To force delete (if branch has unmerged changes):

git branch -D branch-name

Why Use Branches?

  • Work on features without affecting the main code
  • Experiment safely
  • Organize your work
  • Collaborate with others