The Nautilus application development team has been working on a project repository /opt/demo.git. This repo is cloned at _/usr/src/kodekloudrepos_on storage server in Stratos DC. They recently shared the following requirements with DevOps team:
- Create a new branch xfusion in /usr/src/kodekloudrepos/demo repo from master and copy the /tmp/index.html file (present on storage server itself) into the repo. Further, add/commit this file in the new branch and merge back that branch into_master_ branch. Finally, push the changes to the origin for both of the branches.
-
Login to the Storage Server and Gain Root Access:
- Connect to the storage server via SSH.
- Switch to the root user.
ssh natasha@ststor01 sudo su
-
Navigate to the Repository Directory:
- Change to the directory containing the repository.
cd /usr/src/kodekloudrepos/demo
-
Verify the Repository Contents:
- List the files to confirm the repository's state.
ls -al
Expected Output:
total 20 drwxr-xr-x 3 root root 4096 Aug 13 08:02 . drwxr-xr-x 3 root root 4096 Aug 13 08:02 .. drwxr-xr-x 8 root root 4096 Aug 13 08:02 .git -rw-r--r-- 1 root root 34 Aug 13 08:02 info.txt -rw-r--r-- 1 root root 26 Aug 13 08:02 welcome.txt
-
Check the Current Branch:
- Verify the active branch to ensure it’s master.
git branch
Expected Output:
* master
-
Create and Switch to the New Branch:
- Create a new branch named xfusion from master.
- Switch to the new branch.
git checkout -b xfusion
Expected Output:
Switched to a new branch 'xfusion'
-
Move the File from /tmp to the Repository:
- Move the index.html file into the repository directory.
mv /tmp/index.html .
Verify the File Move:
ls -al
Expected Output:
total 24 drwxr-xr-x 3 root root 4096 Aug 13 08:12 . drwxr-xr-x 3 root root 4096 Aug 13 08:02 .. drwxr-xr-x 8 root root 4096 Aug 13 08:10 .git -rw-r--r-- 1 root root 27 Aug 13 08:01 index.html -rw-r--r-- 1 root root 34 Aug 13 08:02 info.txt -rw-r--r-- 1 root root 26 Aug 13 08:02 welcome.txt
-
Add and Commit the Changes:
- Stage the new file and commit the changes with an appropriate message.
git add index.html git commit -m "Add index.html to xfusion branch"
Expected Output:
[xfusion ecaecc9] Add index.html to xfusion branch 1 file changed, 1 insertion(+) create mode 100644 index.html
-
Push the New Branch to the Remote Repository:
- Push the xfusion branch to the remote repository.
git push origin xfusion
Expected Output:
Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 36 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 331 bytes | 331.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To /opt/demo.git * [new branch] xfusion -> xfusion
-
Switch Back to the Master Branch:
- Check out the master branch.
git checkout master
Expected Output:
Switched to branch 'master' Your branch is up to date with 'origin/master'
-
Merge the xfusion Branch into master:
- Merge the changes from xfusion into master.
git merge xfusion
Expected Output:
Updating f9b6eb2..ecaecc9 Fast-forward index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 index.html
-
Push the Updated Master Branch to the Remote Repository:
- Push the changes to the master branch on the remote.
git push origin master
Expected Output:
Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 36 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 331 bytes | 331.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To /opt/demo.git * [new branch] xfusion -> xfusion * [updated] master -> master