hans
) working on your own features but there are some changes from another branch (e.g. release/v1.0.0
) that you need to use, a good practice here would be to get a local copy of the target branch and do a git merge to merge the changes from the release branch into your own branch such as “hans”. A line by line procedure here is shown below using the terminal, a.k.a the command-line:
(show all branches, it's a good practice to check what branch you're on)
git branch -a
Output:
* hans
main
(get release branch from remote repo to local git repo)
git checkout release/v1.0.0
Output:
Branch 'release/v1.0.0' set up to track remote branch 'release/v1.0.0' from 'origin'.
Switched to a new branch 'release/v1.0.0'
(go back to your own branch)
git checkout hans
Output:
Switched to branch 'hans'
Your branch is up to date with 'origin/hans'.
(and merge changes from remote branch to your own branch)
git merge release/v1.0.0
Sounds easy right? Well what if your merge has conflicts? Well not to worry, we will just have to go line by line, one file at a time, to resolve these conflicts using VSCode’s built-in version control features and the merge conflict editor.
After opening VSCode, go to the source control tab on the left and check out the merge changes section. Click on a file and click on the Resolve in Merge Editor button to resolve changes in a clean manner as seen below:
Inside the merge editor, your screen is divided into 3 sections, the incoming changes section on the left, the current file on your branch, and the output of your merging on the bottom.
All these 3 sections scroll up and down together to track your changes, go over them one by one and you can either choose to Accept Incoming changes on the left, or you can keep your own code by clicking Accept Current on the right screen whatever your decision is, they will be shown on the Result screen below, always check the number of conflicts remaining on the right side of the screen and when you’re done, just click on the Complete Merge button.
After resolving all the merge conflicts, run a
git status
in the terminal and see if there are any unstaged changes and run git add .
if there are any, otherwise you can proceed to run a git commit to commit all the merged changes in your local branch and run a git push
to push all your code to your remote repository of your choice.