To merge a branch into another branch in Git, you can use the git merge
command. Here’s an example:
Assume you have two branches named feature
and master
. You want to merge the changes from the feature
branch into the master
branch.
- First, switch to the target branch, which is
master
in this case:
git checkout master
- Then, run the
git merge
command with the name of the branch that you want to merge, which isfeature
in this case:This will merge the changes from thefeature
branch into themaster
branch.
git merge feature
- If there are any conflicts between the branches, Git will prompt you to resolve them manually. You can use a text editor or a merge tool to resolve the conflicts.
- After resolving the conflicts, commit the changes by running the
git commit
command.
git commit -m "Merge feature branch into master branch"
- Finally, push the changes to the remote repository using the
git push
command:
git push origin master
This will push the merged changes to the master
branch on the remote repository.
That’s it! The changes from the feature
branch should now be merged into the master
branch.