git merge
- Git course
- Beginner
- Lesson 57/80
- 4 min
Learn to merge branches with git merge.
What is git merge?
git merge is used to bring changes from one branch into another. The merge operation targets the branch you are currently on and incorporates changes from the specified branch.
git switch main
git merge featureIn this example, changes from the feature branch are merged into main.
The Direction of a Merge
You must be on the target branch before merging. For example, after switching to main, running git merge feature brings the feature changes into main.
git switch main
git merge feature
git statusAfter merging, you can check your working tree with git status.
Practice Build a Merge Command
Assume that you have switched to the main branch. Assign the git merge feature command to a JavaScript variable and print it with console.log().
Starter code
const command = "";
// Komutu yazdırSample solution
const command = "git merge feature";
console.log(command);Expected output
git merge feature
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which branch does a merge operation target?
- The currently checked-out branch Correct answer
- Always the main branch
- The most recently created branch
- The branch specified in the command
Explanation: git merge targets the current branch. Changes from the specified branch are incorporated into it.
2 Specify the Merge Command Target
git switch main
git merge ____
git switch main
git merge feature
Explanation: After switching to main, enter the name of the source branch to merge. Here, the source branch is feature.
3 Merge Concepts
| Term | Meaning |
|---|---|
git merge |
Merges branches |
Mevcut dal |
The branch receiving changes |
Kaynak dal |
The branch providing changes |
git switch main |
Switches to the target branch |