Junior — Middle
How can two branches in a Git repository be merged using the command line?
sobes.tech AI
Answer from AI
To merge two branches in Git using the command line, the git merge command is used.
Example:
- Switch to the branch you want to merge into (for example,
main):
git checkout main
- Perform the merge with another branch (for example,
feature-branch):
git merge feature-branch
If there are no conflicts, the changes from feature-branch will be added to main. In case of conflicts, Git will ask you to resolve them manually.
Alternatively, you can use git rebase for a more linear history, but for a classic merge, git merge is used.