CodeBlanks Logo Icon CodeBlanks

Branch and merge

Create a new branch and complete a merge flow into the main branch.

Develop on a New Branch

When developing a new feature, you can create a separate branch to preserve the current state of the main branch. git branch creates the branch, while git switch moves you to it.

git branch new-feature
git switch new-feature

This lets you develop changes separately from the main branch.

Practice Switch to the Feature Branch

Create a new branch named report and switch to it. Then print a message confirming that the active branch is ready.

Starter code

terminal
print("Dal işlemi başlıyor")

Sample solution

terminal
git branch rapor
git switch rapor
print("Rapor dalı etkin")

Expected output

Dal işlemi başlıyor
Rapor dalı etkin

Practice Merge the Feature Branch into Main

Merge the work from the report branch into the main branch. Print a result message when the merge is complete.

Starter code

terminal
print("Ana dala geçiş hazırlanıyor")

Sample solution

terminal
git switch main
git merge rapor
print("Rapor ana dala birleştirildi")

Expected output

Ana dala geçiş hazırlanıyor
Rapor ana dala birleştirildi

Questions and answers

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

1 Which command sequence creates a new branch and switches to it?

  • git push design followed by git status design
  • git branch design followed by git switch design Correct answer
  • git merge design followed by git add design
  • git commit design followed by git init design

Explanation: Correct. First create the branch with git branch, then switch to it with git switch.

2 Create a New Development Branch

Question
git branch ____
Answer
git branch tasarim

Explanation: The git branch tasarim command creates a new branch named tasarim.

3 Match Branch Operations

Term Meaning
git branch tasarim Creates a new branch
git switch tasarim Switches to the named branch
git merge tasarim Integrates the branch into the current branch
Fast-forward Integrates by moving forward

All lessons in Beginner