Bird
Raised Fist0
Gitdevops~20 mins

Feature branch workflow in Git - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

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
Challenge - 5 Problems
🎖️
Feature Branch Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of creating and switching to a feature branch
What is the output of the following commands when run in a Git repository?

git branch feature-login
git checkout feature-login
Git
git branch feature-login
git checkout feature-login
Aerror: branch 'feature-login' already exists
BSwitched to branch 'feature-login'
Cfatal: not a git repository (or any of the parent directories): .git
DOn branch master
Attempts:
2 left
💡 Hint
The second command switches your working directory to the new branch.
🔀 Workflow
intermediate
2:00remaining
Correct sequence to integrate a feature branch
Which option shows the correct sequence of commands to update your feature branch with the latest changes from the main branch before merging?
Agit checkout main → git pull → git checkout feature → git merge main
Bgit checkout main → git merge feature → git pull
Cgit checkout feature → git merge main → git pull
Dgit checkout feature → git pull → git checkout main → git merge feature
Attempts:
2 left
💡 Hint
You need to update main first, then merge main into your feature branch.
Troubleshoot
advanced
2:00remaining
Resolving a merge conflict in a feature branch
You tried to merge the main branch into your feature branch and got a conflict. What is the correct next step to resolve the conflict?
Git
git checkout feature
git merge main
ADelete the feature branch and recreate it from main
BRun 'git reset --hard' to discard all changes and try merging again
CRun 'git push' immediately to update the remote branch
DEdit the conflicting files to fix conflicts, then run 'git add' on those files and 'git commit' to complete the merge
Attempts:
2 left
💡 Hint
Conflicts must be fixed manually before committing.
Best Practice
advanced
2:00remaining
Best practice for naming feature branches
Which naming style is considered best practice for feature branches in Git?
Afeature/login-page
BLoginPageFeature
Cfeature_login_page
Dloginpagefeature
Attempts:
2 left
💡 Hint
Use lowercase letters and hyphens for readability.
🧠 Conceptual
expert
2:00remaining
Why use feature branches in Git workflows?
What is the main advantage of using feature branches in a Git workflow?
AThey merge all changes directly into the main branch without testing
BThey prevent any code review before merging
CThey isolate development of new features, allowing parallel work without affecting the main codebase
DThey automatically deploy code to production when merged
Attempts:
2 left
💡 Hint
Think about how teams work on different features at the same time.

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

  1. Step 1: Understand the role of feature branches

    Feature branches isolate new development work from the main codebase.
  2. Step 2: Identify the correct purpose

    This isolation allows safe development without affecting the stable main branch.
  3. Final Answer:

    To keep new work separate from the main code until it's ready -> Option C
  4. 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

  1. Step 1: Understand branch creation and switching

    The command git checkout -b branch-name creates and switches to the new branch in one step.
  2. Step 2: Identify the correct command

    git checkout -b feature-login is the command that creates and switches to the new branch.
  3. Final Answer:

    git checkout -b feature-login -> Option D
  4. 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?
git checkout -b feature-ui
 git commit -m "Add UI"
 git checkout main
 git merge feature-ui
medium
A. feature-ui
B. main
C. detached HEAD
D. No branch (error)

Solution

  1. Step 1: Trace branch switching commands

    The commands switch to feature-ui, then back to main.
  2. Step 2: Understand merge and current branch

    After merging feature-ui into main, the current branch remains main.
  3. Final Answer:

    main -> Option B
  4. 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

  1. Step 1: Analyze the error message context

    "Already up to date" means Git sees no new changes to merge.
  2. 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.
  3. Final Answer:

    You are on the wrong branch when merging -> Option A
  4. 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?
hard
A. git checkout main; git merge feature-branch; git push origin main; git branch -d feature-branch
B. git merge feature-branch; git checkout main; git push origin main
C. git checkout feature-branch; git push origin main; git merge main
D. git push origin feature-branch; git checkout main; git merge feature-branch

Solution

  1. Step 1: Switch to main branch before merging

    You must be on main to merge the feature branch into it.
  2. Step 2: Merge, push, and clean up

    After merging, push changes to remote and delete the feature branch locally to keep repo clean.
  3. Final Answer:

    git checkout main; git merge feature-branch; git push origin main; git branch -d feature-branch -> Option A
  4. Quick Check:

    Checkout main, merge, push, delete branch [OK]
Hint: Always merge feature into main, then push and delete branch [OK]
Common Mistakes:
  • Merging without switching to main
  • Pushing wrong branch
  • Not deleting feature branch after merge