CodeBlanks Logo Icon CodeBlanks

Branch management

Complete the branch create, switch and delete flow.

Branch management: create, switch, and delete

When working on a feature, you can create a new branch and continue development there. git switch switches between branches, while git switch -c creates a new branch and switches to it immediately. Once the work is complete and changes are merged, you can delete the unused branch.

git switch -c feature/search
# After development is complete
git switch main
git merge feature/search
git branch -d feature/search

Practice Create and develop a feature branch

Create and switch to a branch named feature/notifications. Then stage the notification.js file and create a commit with the message feat: add notifications.

Starter code

terminal
# Özellik dalını oluştur

# Dosyayı sahnele

# Commit oluştur

Sample solution

terminal
git switch -c feature/notifications
git add notification.js
git commit -m "feat: add notifications"

Expected output

Switched to a new branch 'feature/notifications'
Changes staged.
Commit created.

Practice Merge branch changes and clean up

Feature development is complete. First switch to the main branch, then merge feature/notifications. Finally, safely delete the local feature branch.

Starter code

terminal
# Ana dala geç

# Özellik dalını birleştir

# Özellik dalını sil

Sample solution

terminal
git switch main
git merge feature/notifications
git branch -d feature/notifications

Expected output

Switched to branch 'main'.
Feature branch merged.
Deleted branch feature/notifications.

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Git reports that a branch has not been merged when you try to delete it. What should you do for safe branch management?

  • Reset the entire commit history
  • Force-delete the branch
  • Merge the branch changes first Correct answer
  • Remove the remote repository

Explanation: To avoid losing unmerged changes, merge the branch into the appropriate target branch first, then delete it with -d.

2 Create a branch and return to main

Question
git switch -c feature/notifications
____git switch 
Answer
git switch -c feature/notifications
maingit switch 

Explanation: After creating the new branch, use git switch main to return to the main branch.

3 Branch management operations

Term Meaning
git switch -c Creates and switches to a branch
git switch main Switches to the main branch
git branch -d Safely deletes a local branch
git merge Merges branch changes

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow