Merge
- Git course
- Intermediate
- Lesson 78/82
- 5 min
Merge the approved PR into the main branch and delete the branch.
Merging an approved PR
When a pull request has been reviewed and approved, its changes can be merged into the main branch. After merging, the feature branch can be deleted if it is no longer needed, keeping the repository clean. This operation can involve both the local branch and the remote branch.
git switch main
git merge feature/cart
git branch -d feature/cartBranch cleanup after merging
After a feature branch has been successfully merged, you can delete its local copy with git branch -d. To delete the remote branch, use git push origin --delete. Before deleting a branch, make sure you are on the correct branch and that the merge is complete.
git branch -d feature/cart
git push origin --delete feature/cartPractice Clean up branches after a PR
Assume that the feature/checkout branch has been approved. First switch to main and merge the feature branch. Then delete the local branch and finally remove the remote branch. Write the four commands in the correct order.
Starter code
# Ana dala geç
# Özellik dalını birleştir
# Yerel dalı sil
# Uzak dalı silSample solution
git switch main
git merge feature/checkout
git branch -d feature/checkout
git push origin --delete feature/checkoutExpected output
Switched to branch 'main'. Feature branch merged. Local branch deleted. Remote branch deleted.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command transfers an approved feature branch into the main branch?
- git tag feature/cart
- git merge feature/cart Correct answer
- git restore feature/cart
- git fetch feature/cart
Explanation: While on the main branch, git merge combines the changes from the approved feature branch.
2 Delete the remote feature branch
git push origin ____ feature/checkout
git push origin --delete feature/checkout
Explanation: The --delete option removes the specified branch from origin.
3 Merging and cleanup
| Term | Meaning |
|---|---|
git switch main |
Switches to the main branch |
git merge |
Merges branch changes |
git branch -d |
Deletes the local branch |
--delete |
Deletes the remote branch |