Create a Git Workflow Architecture & Use Hotfix to Push a File — Git Assignment 5
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
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”.
Step 2: Click on “Launch Instances”.
Step 3: Choose “Name” as “Git” in the “Name and tags” section.
Step 4: Choose “AMI” as “Ubuntu” & “AMI Version” as “Ubuntu Server 22.04 LTS (HVM), SSD Volume Type.
Step 5: Choose “Instance type” as “t2.micro”.
Step 6: Choose “Key pair (login)” as “Demo”.
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
Step 8: Click on “Launch Instance”.
Step 9: The instance will be successfully launched. Click on “Hyperlink (i-0915f93c6f548d397)”.
Step 10: The instance will be in the “Running State”.
Step 11: Select the “Instance (Git)” & click on “Connect”.
Step 12: Again, click on “Connect”.
Step 13: The instance will be successfully connected. Run the below-given update command to update the machine.
sudo apt-get update
Step 14: The update will be successfully done.
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
Step 2: Go to the “assignment5” directory using the below-given command:
cd assignment5
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
The “touch.txt” file has been successfully created.
Step 4: Use the below-given command to initialize the “Git”:
git init
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
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"
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
Step 8: Create a New Repository named “Git-Assignment-5” in the “GitHub” account.
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.
Step 10: Click on “Create repository”.
Step 11: The “Git-Assignment-5” Repository will be successfully created.
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
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
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
Step 15: Go outside from the “assignment5” directory using the below-given command:
cd ..
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.
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
Step 18: Run the below-given command to view the public key content:
sudo cat id_rsa.pub
Copy the “public key” content from here.
Step 19: Go to the “GitHub” account. Go to “Settings” in “Profile”.
Step 20: Click on the “SSH and GPG Keys” section.
Step 21: Click on “New SSH Key” in the “SSH Keys” section.
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
Click on “Add SSH Key”.
Step 23: Confirm the “SSH Key” by pasting the password. Click on “Confirm”.
Step 24: “SSH Key” will be successfully added.
Step 25: Exit from .ssh directory using the below-given command:
cd ..
Go to the “Git” machine & go inside the “Git-Assignment-5” directory using the below-given command:
cd assignment5
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.
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.
B. Upload the “GitHub Architecture” Image in the GitHub Account
Step 1: Click on “Add file> Upload files”.
Step 2: Click on “Choose your files”.
Step 3: Choose “Git Workflow Architecture” & click on “Open”.
Step 4: Click on “Commit Changes”.
Step 5: The “Git Workflow Architecture” image has been successfully uploaded.
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
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
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
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
Step 4: Use the below-given command to commit the “f1.txt” file:
git commit –m "committing f1.txt file"
Step 5: Switch to the “feature2” branch using the below-given command:
git checkout feature2
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
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
Step 8: Use the below-given command to commit the “f2.txt” file:
git commit –m "committing 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
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
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
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.
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
Step 2: Run the below-given command to merge the feature1 branch with the “test” branch:
git merge feature1
Step 3: Run the below-given command to checkout any files are present or not:
ls
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.
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
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
Step 2: Go to the “test” branch in the “Git-Assignment-5” repository on “Git hub”.
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.
Step 2: Go to the “master” branch using the below-given command:
git checkout master
Step 3: Run the below-given command to merge the test branch with the “master” branch:
git merge test
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
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
Step 2: Go to the “master” branch in the “Git-Assignment-5” repository on “Git hub”.
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
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
The “hotfix” branch will be successfully created.
Step 2: Go to the “hotfix” branch using the below-given command:
git checkout hotfix
Step 3: Create a file named “urgent.txt” using the below-given command:
touch urgent.txt
Step 4: Stage the “urgent.txt” file using the below-given command:
git add urgent.txt
Step 5: Commit the “urgent.txt” file using the below-given command:
git commit –m "committing 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
The “hotfix” will be successfully pushed.
Step 7: Go to the “Git-Assignment-5” repository & “hotfix” will be successfully updated.
Step 8: Go to the “master” branch using the below-given command:
git checkout master
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.
Step 10: Run the below given command to check out that “urgent.txt” will be shown in the “master” branch or not:
ls
Step 11: Use the below-given command to push the above changes in the “Git-Assignment-5” repository:
git push Git-Assignment-5 master
Step 12: Go to the “master” branch in the “Git-Assignment-5” repository on “Git hub”.
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
Step 14: First, go to the master branch using the below-given command:
git checkout master
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
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
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
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.
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