CodeBlanks Logo Icon CodeBlanks

git merge

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 feature

In 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 status

After 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

terminal
const command = "";

// Komutu yazdır

Sample solution

terminal
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

Question
git switch main
git merge ____
Answer
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

All lessons in Beginner