Let’s look at the full task:
Some new developers have joined xFusionCorp Industries
and have been assigned Nautilus
project. They are going to start development on a new application, and some pre-requisites have been shared with the DevOps team to proceed with. Please note that all tasks need to be performed on storage server
in Stratos
DC.
a. Install git, set up any values for user.email and user.name globally and create a bare repository /opt/official.git
.
b. There is an update
hook (to block direct pushes to the master
branch) under /tmp
on storage server
itself; use the same to block direct pushes to the master
branch in /opt/official.git repo
.
c. Clone /opt/official.git
repo in /usr/src/kodekloudrepos/official
directory.
d. Create a new branch named xfusioncorp_official
in repo that you cloned under /usr/src/kodekloudrepos
directory.
e. There is a readme.md
file in /tmp
directory on storage server
itself; copy that to the repo, add/commit
in the new branch you just created, and finally push your branch to the origin.
f. Also create master
branch from your branch and remember you should not be able to push to the master
directly as per the hook you have set up.
So, general guidelines for this:
- There are no instructions to do otherwise, so I do everything as root.
- I follow the instructions as exactly as I can.
My session looks like this:
## (a)
[root@ststor01 ~]# git init --bare /opt/official.git
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /opt/official.git/
[root@ststor01 ~]# git config --global user.name natasha
[root@ststor01 ~]# git config --global user.email [email protected]
## (c)
[root@ststor01 ~]# ls /tmp
readme.md update
[root@ststor01 ~]# cp /tmp/update /opt/official.git/hooks/
[root@ststor01 ~]# pushd /opt/official.git/hooks/
/opt/official.git/hooks ~
[root@ststor01 hooks]# vi update
## (d)
[root@ststor01 hooks]# git clone /opt/official.git /usr/src/kodekloudrepos/official
Cloning into '/usr/src/kodekloudrepos/official'...
warning: You appear to have cloned an empty repository.
done.
[root@ststor01 hooks]# cd /usr/src/kodekloudrepos/official
[root@ststor01 official]# ls
[root@ststor01 official]# ls -a
. .. .git
[root@ststor01 official]# git checkout -b xfusioncorp_official
Switched to a new branch 'xfusioncorp_official'
## (e)
[root@ststor01 official]# cp /tmp/readme.md .
[root@ststor01 official]# git add .
[root@ststor01 official]# git commit -m 'add readme'
[xfusioncorp_official (root-commit) a55e83e] add readme
1 file changed, 1 insertion(+)
create mode 100644 readme.md
[root@ststor01 official]# git push origin xfusioncorp_official
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 239 bytes | 239.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To /opt/official.git
* [new branch] xfusioncorp_official -> xfusioncorp_official
[root@ststor01 official]# git checkout master
error: pathspec 'master' did not match any file(s) known to git
[root@ststor01 official]# git checkout -b master
Switched to a new branch 'master'
Your branch is based on 'origin/master', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
[root@ststor01 official]# git merge xfusioncorp_official
Already up to date.
[root@ststor01 official]# ls -l
total 4
-rw-r--r-- 1 root root 33 Sep 17 21:18 readme.md
[root@ststor01 official]# git log
commit a55e83e11e469dfb22c344a74682cd32de5e9f9a (HEAD -> master, origin/xfusioncorp_official, xfusioncorp_official)
Author: natasha <[email protected]>
Date: Wed Sep 17 21:19:15 2025 +0000
add readme
## (f)
[root@ststor01 official]# git push origin master
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Manual pushes to the master branch is restricted!!
remote: error: hook declined to update refs/heads/master
To /opt/official.git
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to '/opt/official.git'
The grader accepts this.