0
0
Gitdevops~10 mins

Merge commit creation in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Merge commit creation
Start on branch A
Make commits on branch A
Switch to branch B
Make commits on branch B
Run git merge A on branch B
Git compares changes
If no conflicts
Create merge commit
Merge complete
End with merged history
This flow shows how Git creates a merge commit by combining changes from two branches, handling conflicts if any.
Execution Sample
Git
git checkout main
# On main branch

git checkout -b feature
# Create and switch to feature branch

git add .
git commit -m "Add feature"
# Commit on feature

git checkout main
# Switch back to main

git merge feature
# Merge feature into main
This sequence creates a feature branch, commits changes, then merges it back into main, producing a merge commit.
Process Table
StepCommand/ActionState BeforeGit ActionState After
1git checkout mainOn any branchSwitch to main branchHEAD points to main
2git checkout -b featureOn main branchCreate and switch to feature branchHEAD points to feature, feature branch created
3git commit -m "Add feature"On feature branch with changes stagedCreate commit on featureNew commit added to feature branch
4git checkout mainOn feature branchSwitch back to main branchHEAD points to main
5git merge featuremain and feature branches divergedGit compares commits, creates merge commitmain branch updated with merge commit combining feature
6Merge completeMerge commit createdHistory now includes commits from both branchesBranches merged, working directory updated
💡 Merge commit created successfully, combining changes from feature into main
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
HEADpoints to original branchpoints to featurepoints to featurepoints to mainpoints to mainpoints to main
main branchoriginal commitunchangedunchangedunchangedupdated with merge commitupdated with merge commit
feature branchdoes not existcreated at main commitadvanced by new commitunchangedunchangedunchanged
Key Moments - 3 Insights
Why does Git create a new merge commit instead of just moving the branch pointer?
Because the branches have diverged with different commits, Git needs a merge commit to combine histories, as shown in step 5 of the execution_table.
What happens if there are conflicts during the merge?
Git pauses the merge and asks you to resolve conflicts manually before creating the merge commit, which is not shown here but would interrupt step 5.
Does the merge commit change the feature branch?
No, the merge commit is created on the main branch; the feature branch remains unchanged, as seen in the variable_tracker after step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the state of the feature branch?
AFeature branch is deleted
BFeature branch has a new commit
CFeature branch points to main
DFeature branch has no commits
💡 Hint
Check the 'State After' column for step 3 in the execution_table
At which step does HEAD switch back to the main branch?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look at the 'Command/Action' and 'State After' columns in the execution_table
If there were conflicts during the merge, what would change in the execution flow?
AGit would delete the feature branch
BGit would create the merge commit immediately
CGit would pause and require manual conflict resolution before committing
DGit would switch back to the feature branch automatically
💡 Hint
Refer to the key_moments section about conflict handling
Concept Snapshot
git merge <branch>
- Combines changes from <branch> into current branch
- If branches diverged, creates a merge commit
- If conflicts, manual resolution needed before commit
- Keeps history of both branches intact
- Merge commit has two parents
Full Transcript
This visual execution shows how Git creates a merge commit. First, you start on the main branch, then create and switch to a feature branch. You make a commit on feature, then switch back to main. When you run git merge feature, Git compares the histories. If no conflicts, it creates a merge commit on main combining both branches. The feature branch remains unchanged. If conflicts occur, Git pauses for manual resolution before completing the merge. The merge commit links both histories, preserving all changes.