Git Tasks/Workloads

Git Tasks/Workloads

ยท

3 min read

Task Requirements :

In this article, there are various git tasks to execute which are;

  • Git Install and Create Repository

  • Git Create Branches

  • Git Revert Some Changes

So i will be attempting all the tasks in that order, but we will also be looking at each task's details separately, first is:

Git Install and Create Repo

The development team shared with the DevOps team requirements for new application development, setting up a Git repository for that project. Create a Git repository on the Storage server in the data centre as per the details given below:

  • Install git package using yum on the Storage server.

  • After that, create/init a git repository named /opt/official.git (use the exact name as asked and make sure not to create a bare repository).

Execution:

Navigate into the Storage Server by using the ssh command.

ssh user@ip-address

  • Install the git package using the yum package manager after gaining access to the Server, to do so run;

    sudo yum install git -y

Now we initialise a git repository named /opt/official.git, to do so navigate to the existing directory and run the git init command.

  • Here is how to go about it;

    cd /opt/official.git

    sudo git init

Git Create Branches

Developers are actively working on one of the project repositories, /usr/src/kodekloudrepos/media. Recently, they decided to implement some new features in the application, and they want to maintain those new changes in a separate branch. Below are the requirements that have been shared with the DevOps team:

  • On the Storage server in the data centre, create a new branch xfusioncorp_media from the master branch in /usr/src/kodekloudrepos/media git repo.

  • Please do not try to make any changes in the code.

Execution:

Navigate to the required directory on the Storage Server and run the following commands;

cd /usr/src/kodekloudrepos/media

  • Run these commands to check for the existing branches and know the current branch in your environment, and also create a new branch

    sudo git branch ---> To list all existing branches.

    sudo git checkout master --> To switch to the master branch.

    sudo git branch xfusioncorp_media ---> To create a new branch called xfusioncorp_media from the current branch location master.

Git Revert Some Changes

The application development team was working on a git repository /usr/src/kodekloudrepos/cluster present on the Storage server in the data centre. However, they reported an issue with the recent commits being pushed to this repo. They have asked the DevOps team to revert repo HEAD to last commit. Below are more details about the task:

In /usr/src/kodekloudrepos/cluster git repository, revert the latest commit ( HEAD ) to the previous commit (JFYI the previous commit hash should be with the initial commit message ).

Use "revert cluster" message (please use all small letters for the commit message) for the new revert commit.

Execution:

Navigate to the repository directory /usr/src/kodekloudrepos/cluster and run the following commands;

cd /usr/src/kodekloudrepos/cluster

  • Find the hash of the last two commits

    sudo git log

  • Copy the hash of the commit you want to revert and revert to the latest commit manually

    sudo git reset --hard <commit_hash>

  • Create a new commit with the revert message

    sudo git commit --amend -m "revert cluster"

  • You can check the log to see if the last commit message is now the required commit message "revert cluster"

    sudo git log

ย