Branch and merge
- Git course
- Beginner
- Lesson 79/80
- 6 min
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-featureThis 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
print("Dal işlemi başlıyor")Sample solution
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
print("Ana dala geçiş hazırlanıyor")Sample solution
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
git branch ____
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 |