Photo by Gabriel Heinzer on Unsplash
Merging branches with Git
π‘Git merge command take the independent lines of development created by git branch and integrate them into another branch.
1.- I am going to show you the merge between branches. First, create the update-person-class
branch from the stable
branch. Visit: Creating branches with Git.
2.- See all branches with git branch
command.
git branch
3.- Enter inside the stable
branch with git checkout <branch_name_to_receive_merge>
command, because I am going to merge the update-person-class
branch inside the stable
branch.
git checkout stable
4.- In this example, the file 30class
is different in every branch.
File 30class
in stable
branch:
File 30class
in update-person-class
branch:
5.- Merge branches with git merge <new_branch>
command. In this example, I am going to merge the update-person-class
branch inside the stable
branch.
git merge update-person-class
6.- Push changes with git push origin main
command from the local repository to the remote repository.
git push origin stable
7.- The file is updated in the stable
branch.
8.- Delete the deprecated branch with git branch -d <new_branch>
command.
git branch -d update-person-class
9.- If there are conflicts between the branches, you can solve them in Visual Studio Code.
10.- You can continue with git merge --continue
command after you fix the conflicts.
git merge --continue