Create a Git Workflow Architecture & Use Hotfix to Push a File — Git Assignment 5

Visal Tyagi
DevOps-Guides
Published in
16 min readMay 27, 2024

Tasks to Be Performed:

1. Create a Git Flow workflow architecture on Git

2. Create all the required branches

3. Starting from the feature branch, push the branch to the master, following the architecture

4. Push a urgent.txt on master using hotfix

Check the Git Hub Repository for this Assignment to Copy the Commands:

Problem (1) Solution: Create a Git Flow workflow architecture on Git

Git Work Flow Architecture — Git Assignment 5
Git Workflow Architecture — Git Assignment 5

Step 1: First, we will create a main.txt file under the “master” branch.

Step 2: Create the feature1 branch & here, create the “feature1.txt” file.

Step 3: Create the feature2 branch & here, create the “feature2.txt” file.

Step 4: Instead of directly merging with the master, we will create a new branch “test” & it is a precautionary branch to verify the work done. Merge feature1 & feature2 branches with the “test” branch.

Step 5: Merge “test” with “master”.

Step 6: If the release date is the 9th of April & the client wants to add an urgent.txt file in the “master”. We don’t go to “feature1” & “feature2” because we have to repeat all the processes one by one here. It’s a tidy process.

Step 7: If our release date is on 09th April & we have a last-minute change, we will create a branch from the master named “hotfix”. Here, create the “urgent.txt” file & merge the “hotfix” branch with “master”.

Step 8: After merging the branch, we will delete the “hotfix” branch. Now, the last-minute changes will be successfully done in “master” & we are ready to release the product.

A. Create an EC2 Instance for Performing this Assignment

Step 1: Go to the “Services” section & search “EC2” here. Put Cursor over “EC2” & click on “Instances”.

Search EC2 & Click on Instances
Search EC2 & Click on Instances

Step 2: Click on “Launch Instances”.

Go to Launch Instance
Go to Launch Instance

Step 3: Choose “Name” as “Git” in the “Name and tags” section.

Write Instance Name
Write Instance Name

Step 4: Choose “AMI” as “Ubuntu” & “AMI Version” as “Ubuntu Server 22.04 LTS (HVM), SSD Volume Type.

Choose AMI
Choose AMI

Step 5: Choose “Instance type” as “t2.micro”.

Instance Type
Instance Type

Step 6: Choose “Key pair (login)” as “Demo”.

Choose Key Pair
Choose Key Pair

Step 7: In “Network Settings”, choose the following options here:

Firewall (security groups): — Select existing security group

Common security groups: — launch-wizard-9 sg-00ebfbf131243e93d

Select the Security Group
Select the Security Group

Step 8: Click on “Launch Instance”.

Launch Instance

Step 9: The instance will be successfully launched. Click on “Hyperlink (i-0915f93c6f548d397)”.

Instance Launched Successfully
Instance Launched Successfully

Step 10: The instance will be in the “Running State”.

Running Instance
Running Instance

Step 11: Select the “Instance (Git)” & click on “Connect”.

Select the Instance
Select the Instance

Step 12: Again, click on “Connect”.

Connect the Instance
Connect the Instance

Step 13: The instance will be successfully connected. Run the below-given update command to update the machine.

sudo apt-get update
Update the Git Machine
Update the Git Machine

Step 14: The update will be successfully done.

Update the Git Machine
Machine Updated Successfully

B. In the master branch, commit the main.txt file

Step 1: First, we will create a separate directory using the below-given command:

mkdir assignment5

Run the below-given command to check the directory will be created or not:

ls  
Create a directory
Create a directory

Step 2: Go to the “assignment5” directory using the below-given command:

cd assignment5
Go to assignment5 directory
Go to assignment5 directory

Step 3: Create a “main.txt” file using the below-given command:

touch main.txt

Run the below-given command to check whether the “touch.txt” file is created or not:

ls  
main.txt created
main.txt created

The “touch.txt” file has been successfully created.

Step 4: Use the below-given command to initialize the “Git”:

git init
Initialize Git
Initialize Git

The “Git” remote will be successfully initialized.

Step 5: Now, add or stage the “main.txt” file in “Git” using the below-given command:

git add main.txt

Use the below-given command to check whether that “main.txt file” is added or not.

git status
Stage the “main.txt” file
Stage the “main.txt” file

Step 6: Now, we will commit the “main.txt” file in the “master” branch using the below-given command:

git commit –m "committing main.txt"
Commit “main.txt” file
Commit “main.txt” file

The “main.txt” file will be successfully committed in the “master” branch.

Step 7: Use the below-given command to check out the content of the “master” branch:

git show-branch master
Show master branch content
Show master branch content

Step 8: Create a New Repository named “Git-Assignment-5” in the “GitHub” account.

Create New Repository
Create New Repository

Click on “New”.

Step 9: Choose the following options here:

Repository Name: — Git-Assignment-5

Description: — Git Assignment 5

Choose the “Public” option to make this repository public.

Create a Repository
Create a Repository

Step 10: Click on “Create repository”.

Click “Create repository”
Click “Create repository”

Step 11: The “Git-Assignment-5” Repository will be successfully created.

Git-Assignment-5
Git-Assignment-5

Step 12: Now, go to “Git” machine & use the below-given command to add “Repository URL”:

git remote add Git-Assignment-5 git@github.com:visaltyagi/Git-Assignment-5.git
Add to Local Repository
Add to Local Repository

The repository (Git-Assignment-5) will be successfully added.

Step 13: To check whether the GitHub Repository (Git-Assignment-5) will be added or not, use the below-given command:

git remote –v
Remote Repo Shows
Remote Repo Shows

It will show the repository URL here.

Step 14: Run the below-given command to check how many branches are present in the “Git-Assignment-5 repository”.

git branch
Checkout Branches
Checkout Branches

Step 15: Go outside from the “assignment5” directory using the below-given command:

cd ..
Exit from Assignment 5 Directory
Exit from Assignment 5 Directory

Step 16: Create the public key using the below-given command:

ssh-keygen

Press “enter” three times, and both public & private keys will be successfully added.

SSH Key Generated
SSH Key Generated

Step 17: Go to the .ssh directory using the below-given command:

cd .ssh

Run the below-given command to check that “keys” are created or not.

ls  
Check Keys are Created or Not
Check Keys are Created or Not

Step 18: Run the below-given command to view the public key content:

sudo cat id_rsa.pub
Copy the public key content
Copy the public key content

Copy the “public key” content from here.

Step 19: Go to the “GitHub” account. Go to “Settings” in “Profile”.

Go to Settings
Go to Settings

Step 20: Click on the “SSH and GPG Keys” section.

Go to “SSH and GPG Keys”
Go to “SSH and GPG Keys”

Step 21: Click on “New SSH Key” in the “SSH Keys” section.

New SSH Key
New SSH Key

Step 22: Choose “Title” as “SSH Key”, while pasting the public key content in the “Key” section.

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCL8RTqXMmDanpw30Ui0g08GWUGqrSxzdrYltw72+Urq/3RhzHIttdmHWxQsyoPVHSXRRQLKxrecjZCzOtia33o2zM4fX7HOW43QCIwEzCd3iC+AjO0rfRTYQLItdIbA6068dQ3lCEdOLtOfDLwtgle/N+ajHh+h5e/8Z/IkqVQUe+FjvWkv5lqK0yR7zj0FTweukOJ+YQxRsxlJBR6nmQ1N5UlXylCLDUfFW8ctOEhJ2ivx0OuKBAh87QhwGg5i8a4Ved4THqqVXtMXgrZwuIk2rT7SeXW0x/aiZo5HueqM2jnspr5rA3J0YQq5lniuZS59j53O0JLKFDzzRul4F6q5PsOhMZXH+SVwSRviooWE+PWroyO9ZTCXmzLAWvsuCPzj3VoWu+jX5A/szziwHHB+kLEzcZg3bLZhnUdF8Kg774n0ZmwyGYyxKqHjm3nWksuyGRPAaXtnYoP5b9fBV2eSy/2nqnFWKoBtQ7xomtJd2rPZNfFm/1AmnAFA0EVex0= ubuntu@ip-172–31–47–214

Add SSH Key
Add SSH Key

Click on “Add SSH Key”.

Step 23: Confirm the “SSH Key” by pasting the password. Click on “Confirm”.

Confirm Access
Confirm Access

Step 24: “SSH Key” will be successfully added.

SSH Key Added
SSH Key Added

Step 25: Exit from .ssh directory using the below-given command:

cd ..
Change the directory
Change the directory

Go to the “Git” machine & go inside the “Git-Assignment-5” directory using the below-given command:

cd assignment5
Go to the “assignment5” directory
Go to the “assignment5” directory

Step 26: Put this URL to push the branch in the “Git-Assignment-5” repository.

Run this command:

git push Git-Assignment-5 master

Type “yes” to continue.

Master Pushed to Remote Repository
Master Pushed to Remote Repository

Press “enter” from the keyboard & “master” repo will be successfully pushed to the “Git-Assignment-5” repository.

Step 27: Go to “Github Repository: Git-Assignment-5” & refresh the browser.

main.txt file in Remote Repository
main.txt file in Remote Repository

B. Upload the “GitHub Architecture” Image in the GitHub Account

Step 1: Click on “Add file> Upload files”.

Upload the File
Upload the File

Step 2: Click on “Choose your files”.

Choose your files
Choose your files

Step 3: Choose “Git Workflow Architecture” & click on “Open”.

Git Workflow Architecture Image
Git Workflow Architecture Image

Step 4: Click on “Commit Changes”.

Commit the Changes
Commit the Changes

Step 5: The “Git Workflow Architecture” image has been successfully uploaded.

Git Workflow Architecture Image
Git Workflow Architecture Image

Problem (2) Solution: Create all the required branches

A. Create the Required Branches

Step 1: Now, we will create the three branches such as “test”, “feature1” & “feature2”.

Use these below-given commands:

git branch test
git branch feature1
git branch feature2

Now, we will run the below-given command to check out how many branches are created:

git branch
Branch Created
Branch Created

All the branches (test, feature1, feature2) will be successfully created

B. Put f1.txt in feature1 branch, f2.txt feature2 branch respectively

Step 1: Switch to the “feature1” branch using the below-given command:

git checkout feature1
Feature1
Feature1

You will be successfully switched to the “feature1” branch.

Step 2: Create an “f1.txt” file using the below-given command:

touch f1.txt

Check the file creation, use the below-given command:

git status
f1.txt created
f1.txt created

It will ask to add this file. Now, we will perform the stage & commit to the “f1.txt” file in the “feature1” branch.

Step 3: Use the below-given command to stage the “f1.txt” file:

git add f1.txt
f1.txt staged
f1.txt staged

Step 4: Use the below-given command to commit the “f1.txt” file:

git commit –m "committing f1.txt file"
Commit the “f1.txt” file
Commit the “f1.txt” file

Step 5: Switch to the “feature2” branch using the below-given command:

git checkout feature2
Switch to feature2 branch
Switch to feature2 branch

You will be successfully switched to the “feature2” branch.

Step 6: Create an “f2.txt” file using the below-given command:

touch f2.txt

Check the file creation, use the below-given command:

git status
Create the f2.txt file
Create the f2.txt file

It will ask to add this file. Now, we will perform the stage & commit to the “f2.txt” file in the “feature2” branch.

Step 7: Use the below-given command to stage the “f2.txt” file:

git add f2.txt
Stage the f2.txt file
Stage the f2.txt file

Step 8: Use the below-given command to commit the “f2.txt” file:

git commit –m "committing f2.txt file"
Commit the f2.txt file
Commit the f2.txt file

C. Push all these branches (test, feature1, feature2) to GitHub

Now, we will push all the branches to the repository (Git-Assignment-5).

Step 1: Now, use the below-given command to push the “feature1” branch in “GitHub Repository”:

git push Git-Assignment-5 feature1
Push the feature1 branch to Remote Repository
Push the feature1 branch to Remote Repository
feature1 on Remote Repository
feature1 on Remote Repository

The “feature1” branch will be successfully pushed to “The Git Hub repository (Git-Assignment-5).

Step 2: Now, use the below-given command to push the “feature2” branch in “GitHub Repository”:

git push Git-Assignment-5 feature2
Push feature2 branch to Remote Repository
Push feature2 branch to Remote Repository
feature2 pushed on remote repository
feature2 pushed on remote repository

The “feature2” branch will be successfully pushed to “Git Hub repository (Git-Assignment-5).

Step 3: Now, use the below-given command to push the “test” branch in “GitHub Repository”:

git push Git-Assignment-5 test
Push test branch to remote repository
Push test branch to remote repository
test branch on remote repository
test branch on remote repository

No content will be shown here at the beginning of this branch.

Step 4: Go to the “GitHub account” & also, you will notice the message that “test”, “feature1” & “feature2” have recent pushes available.

Branches on Remote Repository
Branches on Remote Repository

Refresh the repository (Git-Assignment-5) & all the branches will be shown successfully.

Problem (3) Solution: Starting from the feature branch, push the branch to the master, following the architecture

Follow these steps here:

A. Merge feature1 & feature2 branches with “test” branch

Step 1: Go to the “test” branch using the below-given command:

git checkout test
Switch to “test” branch
Switch to “test” branch

Step 2: Run the below-given command to merge the feature1 branch with the “test” branch:

git merge feature1
Merge feature1
Merge feature1

Step 3: Run the below-given command to checkout any files are present or not:

ls
f1.txt file shown here
f1.txt file shown here

The “f1.txt” will be shown in the “test” branch.

Step 4: Run the below-given command to merge the “feature2” branch with the “test” branch:

git merge feature2

A pop will be shown. Do “CTRL+S” to save the file & “CTRL+X” to exit from the file.

Save the file
Save the file
f2.txt in test branch
f2.txt in test branch

The “f2.txt” will be successfully merged in the “test” branch.

Step 5: Run this command to check out the f2.txt file is shown or not here:

ls  
f2.txt file shown here
f2.txt file shown here

The “f2.txt” will be shown in the “test” branch.

B. Again, Push Changes to the Test Branch

Step 1: Use the below-given command to push the above changes in the “Git-Assignment-5” repository:

git push Git-Assignment-5 test
Again, Push “Test” to the Remote Repository
Again, Push “Test” to the Remote Repository

Step 2: Go to the “test” branch in the “Git-Assignment-5” repository on “Git hub”.

Files in “test branch”
Files in “test branch”

Both “f1.txt” & “f2.txt” will be shown in the “Git-Assignment-5” repository because we have pushed both files in the “test” branch.

C. Merge test branches with the “master” branch

Step 1: The “master” branch only has the “main.txt” file, here we don’t have merged anything.

The “master” branch
The “master” branch

Step 2: Go to the “master” branch using the below-given command:

git checkout master
Switch to the “master” branch
Switch to the “master” branch

Step 3: Run the below-given command to merge the test branch with the “master” branch:

git merge test
Merge test with master branch
Merge test with master branch

Both the files “f1.txt & “f2.txt” will be added to the “master” branch.

Step 3: Run the below-given command to check out these files:

ls  
Files Shown Here
Files Shown Here

The “f1.txt” & “f2.txt” will be shown in the “master” branch.

D. Push Changes to Git-Assignment-5 Repository

Step 1: Use the below-given command to push the above changes in the “Git-Assignment-5” repository:

git push Git-Assignment-5 master
Push master to remote repository
Push master to remote repository

Step 2: Go to the “master” branch in the “Git-Assignment-5” repository on “Git hub”.

All Files Shown in master branch
All Files Shown in master branch

Both “f1.txt” & “f2.txt” will be shown in the “Git-Assignment-5” repository because we have pushed both files in the “master” branch.

Step 3: If you want to know “test” is merged with the “master” branch or not.

Use the below-given command:

git reflog
Git Reflog Command
Git Reflog Command

Problem (4) Solution: Push an urgent.txt on master using hotfix

Step 1: Create a branch named “hotfix” using the elow-given command:

git branch hotfix
Hotfix Branch
Hotfix Branch

The “hotfix” branch will be successfully created.

Step 2: Go to the “hotfix” branch using the below-given command:

git checkout hotfix
Switch to the “hotfix” branch
Switch to the “hotfix” branch

Step 3: Create a file named “urgent.txt” using the below-given command:

touch urgent.txt
urgent.txt file created
urgent.txt file created

Step 4: Stage the “urgent.txt” file using the below-given command:

git add urgent.txt
Stage the urgent.txt file
Stage the urgent.txt file

Step 5: Commit the “urgent.txt” file using the below-given command:

git commit –m "committing urgent.txt file"
Commit the urgent.txt file
Commit the urgent.txt file

Step 6: Push the “hotfix” branch to the Git Hub repository using the below-given command:

git push Git-Assignment-5 hotfix
Push Hotfix to Remote Repository
Push Hotfix to Remote Repository

The “hotfix” will be successfully pushed.

Step 7: Go to the “Git-Assignment-5” repository & “hotfix” will be successfully updated.

urgent.txt in “remote master branch”
urgent.txt in “remote master branch”

Step 8: Go to the “master” branch using the below-given command:

git checkout master
Switch to the “master” branch
Switch to the “master” branch

Step 9: Run the below-given command to merge the hotfix branch with the “master” branch:

git merge hotfix

A pop will be shown. Do “CTRL+S” to save the file & “CTRL+X” to exit from the file.

Save the file
Save the file
hotfix successfully merged
hotfix successfully merged

Step 10: Run the below given command to check out that “urgent.txt” will be shown in the “master” branch or not:

ls  
urgent.txt shown here
urgent.txt shown here

Step 11: Use the below-given command to push the above changes in the “Git-Assignment-5” repository:

git push Git-Assignment-5 master
Again push master to remote repository
Again push master to remote repository

Step 12: Go to the “master” branch in the “Git-Assignment-5” repository on “Git hub”.

The urgent.txt successfully pushed to remote repo
The urgent.txt successfully pushed to remote repo

The “urgent.txt” will be shown in the “Git-Assignment-5” repository because we have pushed both files to the “master” branch.

Step 13: If you want to know if “hotfix” is merged with the “master” branch or not. Use the below-given command:

git reflog
Checkout Merging
Checkout Merging

Step 14: First, go to the master branch using the below-given command:

git checkout master
Switch to the master branch
Switch to the master branch

You will be successfully moved to the “master” branch.

Step 15: Now, we will delete the “hotfix” branch from the remote using the below-given command:

git branch –D hotfix
Delete the hotfix branch
Delete the hotfix branch

The “hotfix” branch will be successfully deleted from the local “EC2” instance.

Step 16: Run the below-given command to check out how many branches are available:

git branch
Checkout the branches
Checkout the branches

The “hotfix” branch will not be shown here now.

Step 17: Now, we will delete the branch from the “local” using the below-given command:

git push Git-Assignment-3 –delete hotfix
delete the hotfix branch from remote repository
delete the hotfix branch from remote repository

The “hotfix” branch will be successfully deleted from the repository also.

Step 18: Go to “GitHub Repository” & refresh the browser. Click on “master” & “hotfix” branches will not be shown here.

Hotfix Branch Delete from Remote Repository
Hotfix Branch Delete from Remote Repository

So, this is the whole concept of “hotfix” in “Git flow workflow architecture”.

Checkout these Git Assignment Solutions:

Create The Files & Push them to Git Hub Repository — Git Assignment 1

Create the Files in Separate Branches And Perform Stash & Unstash Operations — Git Assignment 2

Create & Delete the Branches in Git Hub from Local & Remote Repository — Git Assignment 3

Create Two Branches & Merge These Branches to the Master Branch — Git Assignment 4

Check these Git Case Studies Also:

Suggested a Git Workflow Architecture to Manage the Product Release — Git Case Study 1

Resolve Merge Conflict in The GitHub Repository — Git Case Study 2

--

--