Git Setup from Scratch

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/media.git.

b. There is an update hook (to block direct pushes to master branch) under /tmp on storage server itself; use the same to block direct pushes to master branch in /opt/media.git repo.

c. Clone /opt/media.git repo in /usr/src/kodekloudrepos/media directory.

d. Create a new branch xfusioncorp_media in repo that you cloned in /usr/src/kodekloudrepos.

e. There is a readme.md file in /tmp on storage server itself; copy that to repo, add/commit in the new branch you created, and finally push your branch to origin.

f. Also create master branch from your branch and remember you should not be able to push to master as per hook you have set up.

Solution :

[root@ststor01 natasha]# cat /etc/os-release
[root@ststor01 natasha]# yum install git -y
[root@ststor01 natasha]# git config --global --add user.name natasha
[root@ststor01 natasha]# git config --global --add user.email natasha@xfusioncorp.com
[root@ststor01 natasha]# git init --bare /opt/media.git
Initialized empty Git repository in /opt/media.git/
[root@ststor01 natasha]# cd /opt/media.git/
[root@ststor01 media.git]# cp /tmp/update hooks/
[root@ststor01 media.git]# cd /usr/src/kodekloudrepos/
[root@ststor01 kodekloudrepos]# git clone /opt/media.git
Cloning into 'media'...
warning: You appear to have cloned an empty repository.
done.
[root@ststor01 kodekloudrepos]# cd media/
[root@ststor01 media]# git checkout -b xfusioncorp_media
Switched to a new branch 'xfusioncorp_media'
[root@ststor01 media]# cp /tmp/readme.md .
[root@ststor01 media]# git add readme.md
[root@ststor01 media]# git commit -m "Readme file"
[xfusioncorp_media (root-commit) 8b745fb] Readme file
1 file changed, 1 insertion(+)
create mode 100644 readme.md
[root@ststor01 media]# git push origin xfusioncorp_media
Counting objects: 3, done.
Writing objects: 100% (3/3), 245 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /opt/media.git
* [new branch] xfusioncorp_media -> xfusioncorp_media
[root@ststor01 media]# git checkout -b master
Switched to a new branch 'master'
[root@ststor01 media]# git push origin master
Total 0 (delta 0), reused 0 (delta 0)
remote: Manual pushing to this repo's master branch is restricted
remote: error: hook declined to update refs/heads/master
To /opt/media.git
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to '/opt/media.git'
[root@ststor01 media]#

Leave a Reply

Your email address will not be published. Required fields are marked *