Git Setup from Scratch

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 and 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 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 :

[[email protected] natasha]# cat /etc/os-release
[[email protected] natasha]# yum install git -y
[[email protected] natasha]# git config --global --add natasha
[[email protected] natasha]# git config --global --add [email protected]
[[email protected] natasha]# git init --bare /opt/media.git
Initialized empty Git repository in /opt/media.git/
[[email protected] natasha]# cd /opt/media.git/
[[email protected] media.git]# cp /tmp/update hooks/
[[email protected] media.git]# cd /usr/src/kodekloudrepos/
[[email protected] kodekloudrepos]# git clone /opt/media.git
Cloning into 'media'...
warning: You appear to have cloned an empty repository.
[[email protected] kodekloudrepos]# cd media/
[[email protected] media]# git checkout -b xfusioncorp_media
Switched to a new branch 'xfusioncorp_media'
[[email protected] media]# cp /tmp/ .
[[email protected] media]# git add
[[email protected] media]# git commit -m "Readme file"
[xfusioncorp_media (root-commit) 8b745fb] Readme file
1 file changed, 1 insertion(+)
create mode 100644
[[email protected] 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
[[email protected] media]# git checkout -b master
Switched to a new branch 'master'
[[email protected] 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'
[[email protected] media]#

Leave a Reply

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