In distributed version control systems like Git, development is performed in isolation using branches. Merging is the process of integrating changes from one branch (typically a feature or hotfix branch) back into another branch (usually the default branch, such as master or main).
ff):
master) has no new commits since the source branch (nautilus) was created.master branch pointer forward to the commit at the tip of the nautilus branch. No new merge commit is created.Before: A --- B (master)
\
C --- D (nautilus)
After: A --- B --- C --- D (master, nautilus)
master) has diverged and received new commits after the source branch (nautilus) was branched.Before: A --- B --- E (master)
\
C --- D (nautilus)
After: A --- B --- E --- F (master)
\ /
C ----- D (nautilus)
A merge conflict occurs when the same line of the same file has been modified differently in both branches. Git cannot automatically determine which version is correct, so it halts the merge process and marks the file as conflicted:
<<<<<<< HEAD
<h1>This is the master branch title</h1>
=======
<h1>This is the feature branch title</h1>
>>>>>>> nautilus
<<<<<<< HEAD: Indicates the beginning of changes in the current checked-out branch.=======: Serves as the divider line between the two versions.>>>>>>> nautilus: Indicates the end of changes in the branch being merged.Resolution Steps:
<<<<<<<, =======, >>>>>>>).git add <file>.git commit -m "Resolve merge conflict".This guide outlines the steps to connect to the Nautilus Storage Server, create a branch, add a file, merge it into master, and push the updates.
ststor01)natasha (or designated sudo user)/usr/src/kodekloudrepos/ecommercenautilusmaster/tmp/index.htmlFrom the Jump Host, SSH into the storage server:
ssh natasha@ststor01
Change directory to the designated local git repository:
cd /usr/src/kodekloudrepos/ecommerce
Create a new branch named nautilus and switch to it immediately:
git checkout -b nautilus
Alternatively, you can use: git branch nautilus && git checkout nautilus.
Copy the staging file into the repository, stage it, and create a commit on the nautilus branch:
# 1. Copy the file from /tmp to the repository folder
cp /tmp/index.html .
# 2. Stage the new file
git add index.html
# 3. Commit the changes
git commit -m "Add index.html on nautilus branch"
Navigate back to the main branch (master) where the changes will be merged:
git checkout master
Merge the changes from the nautilus branch into the current checked-out branch (master):
git merge nautilus
Since master has not received any updates in this interval, Git will perform a Fast-Forward merge.
Push both the updated master branch and the new nautilus branch to the central remote repository:
# 1. Push master branch updates
git push origin master
# 2. Push nautilus branch
git push origin nautilus
Display a visual representation of your branch history and commits:
git log --graph --oneline --all
Expected output showing the commit integrated into master:
* d3b49c0 (HEAD -> master, origin/nautilus, origin/master, nautilus) Add index.html on nautilus branch
* b82e01a Initial commit
Verify that the remote repository tracking branches are up to date:
git branch -a
Expected output:
* master
nautilus
remotes/origin/master
remotes/origin/nautilus
Log out of the Storage Server:
exit