Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Feature Branch Workflow with Git
📖 Scenario: You are working on a team project using Git. Your team uses a feature branch workflow to keep the main branch stable. Each new feature is developed in its own branch and merged back only when ready.
🎯 Goal: Learn how to create a feature branch, make a commit, and merge it back into the main branch using Git commands.
📋 What You'll Learn
Create a new branch called feature-login from main
Make a commit with a message Implement login feature
Switch back to main branch
Merge the feature-login branch into main
💡 Why This Matters
🌍 Real World
Teams use feature branches to work on new features safely without breaking the main code. This keeps the project stable and organized.
💼 Career
Knowing how to use feature branches is essential for collaboration in software development jobs and DevOps roles.
Progress0 / 4 steps
1
Create a feature branch
Use the command git branch feature-login to create a new branch called feature-login from the current main branch.
Git
Hint
Use git branch followed by the branch name to create a new branch.
2
Switch to the feature branch
Use the command git checkout feature-login to switch to the feature-login branch.
Git
Hint
Use git checkout followed by the branch name to switch branches.
3
Make a commit on the feature branch
Use git commit -m "Implement login feature" to create a commit with the message Implement login feature on the feature-login branch.
Git
Hint
Use git commit -m with your message in quotes to commit changes.
4
Switch back and merge the feature branch
First, switch back to the main branch using git checkout main. Then merge the feature-login branch into main using git merge feature-login.
Git
Hint
Use git checkout main to switch back, then git merge feature-login to merge the feature branch.
Practice
(1/5)
1. What is the main purpose of using a feature branch in Git?
easy
A. To merge all changes immediately without review
B. To delete the main branch permanently
C. To keep new work separate from the main code until it's ready
D. To create backups of the repository
Solution
Step 1: Understand the role of feature branches
Feature branches isolate new development work from the main codebase.
Step 2: Identify the correct purpose
This isolation allows safe development without affecting the stable main branch.
Final Answer:
To keep new work separate from the main code until it's ready -> Option C
Quick Check:
Feature branch purpose = isolation [OK]
Hint: Feature branches isolate new work from main code [OK]
Common Mistakes:
Thinking feature branches delete main branch
Assuming feature branches merge immediately
Confusing feature branches with backups
2. Which Git command correctly creates and switches to a new feature branch named feature-login?
easy
A. git branch feature-login
B. git push feature-login
C. git merge feature-login
D. git checkout -b feature-login
Solution
Step 1: Understand branch creation and switching
The command git checkout -b branch-name creates and switches to the new branch in one step.
Step 2: Identify the correct command
git checkout -b feature-login is the command that creates and switches to the new branch.
Final Answer:
git checkout -b feature-login -> Option D
Quick Check:
Create and switch branch = git checkout -b [OK]
Hint: Use git checkout -b to create and switch branch [OK]
Common Mistakes:
Using git branch without switching
Confusing git merge with branch creation
Trying to push before creating branch
3. Given the commands below, what will be the current branch after execution?
The commands switch to feature-ui, then back to main.
Step 2: Understand merge and current branch
After merging feature-ui into main, the current branch remains main.
Final Answer:
main -> Option B
Quick Check:
Last checkout branch = current branch [OK]
Hint: Last git checkout sets current branch [OK]
Common Mistakes:
Assuming merge switches branch
Confusing commit branch with current branch
Thinking merge detaches HEAD
4. You created a feature branch and made commits, but when you try to merge it into main, Git says "Already up to date." What is the likely problem?
medium
A. You are on the wrong branch when merging
B. Your working directory has uncommitted changes
C. The feature branch has diverged from main
D. You forgot to push the feature branch to remote
Solution
Step 1: Analyze the error message context
"Already up to date" means Git sees no new changes to merge.
Step 2: Check the branch where merge is run
If you run git merge feature-branch while not on main, it merges into the wrong branch or shows no effect.
Final Answer:
You are on the wrong branch when merging -> Option A
Quick Check:
Merge branch context matters [OK]
Hint: Always checkout main before merging feature branch [OK]
Common Mistakes:
Merging while on feature branch instead of main
Assuming push affects local merge
Ignoring branch status before merge
5. Your team uses feature branches. You finished a feature and want to merge it into main. Which sequence of commands correctly follows the feature branch workflow?