Create Two Branches & Merge These Branches to the Master Branch — Git Assignment 4
Tasks to Be Performed:
1. Put master.txt on the master branch, stage, and commit
2. Create 3 branches: public 1, public 2 and private
3. Put public1.txt on public 1 branch, stage, and commit
4. Merge public 1 on the master branch
5. Merge public 2 on the master branch
6. Edit master.txt on a private branch, stage, and commit
7. Now update branch public 1 and public 2 with new master code in private
8. Also update the new master code on the master
9. Finally update all the code on the private branch
Before Checking this Assignment, kindly check these assignments:
Note: We have created an EC2 instance named as “Git”, you have to create an instance before performing this assignment. For creating the instance, you can check “Git-Assignment-1” Solution.
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
Check the Git Hub Repository for this Assignment to Copy the Commands:
Note: We have created an EC2 instance named as “assignment4”, you can create an instance before performing this assignment.
Problem (1) Solution: Put master.txt on the master branch, stage, and commit
Step 1: First, create an “assignment4” directory using the below-given command:
mkdir assignment4
Run the below-given command & the “assignment4” directory will be shown here.
ls
Step 2: Go to the “assignment4” directory using the below-given command:
cd assignment4
Step 3: Create a “master.txt” file using the below-given command:
touch master.txt
Run the below-given command & you will notice that “master.txt” has been created:
ls
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 “master.txt” file in “Git” using the below-given command:
git add master.txt
Use the below-given command to check whether the “master.txt file” is added or not.
git status
Step 6: Now, we will commit the “master.txt” file in the “master” branch using the below-given command:
git commit –m "committing master.txt ".
The “master.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 as “Git-Assignment-4” in the “GitHub” account.
Click on “New”.
Step 9: Choose the following options here:
Repository Name: — Git-Assignment-4
Description: — Git Assignment 4
Choose the “Public” option to make this repository public.
Step 10: Enable the option “Add a README file” by choosing this option.
Step 11: The “Git-Assignment-4” Repository will be successfully created.
Step 12: Now, go to the “Git” machine & use the below-given command to add “Repository URL”:
git remote add Git-Assignment-4 git@github.com:visaltyagi/Git-Assignment-4.git
The repository (Git-Assignment-4) will be successfully added.
Step 13: To check whether the GitHub Repository (Git-Assignment-4) 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-3 repository”:
git branch
Step 15: Exit from “assignment4” 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 & the “id_rsa.pub” will be shown:
ls
Step 18: Run the below-given command to view the public key content:
sudo cat id_rsa.pub
Copy this content of the public key 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 AAAAB3NzaC1yc2EAAAADAQABAAABgQCtplZNy+2HNhjzuH9ZYDhU+H4D+kCKvfmjzdWA7XTPIW/8iE5sCEZV9rLAWg7Xi//KXAilZwNYVXZ75OsadSXSYDCN5xngK3U+cXk3n9LbOXkCVrLeSllkKv7evL6QH7egKf06RqcuF/dJga22lnv8JmwmixJPg+V62CwpO3LSbXZfzya1oCpBTJ/EOXUcsmXtmvM+xPUBP9e1lo9EPODiFD2uLhZHMC2N7OhpEK3Mn9MtQsi2anzm2BDDetVY55Y4gb5bUHCQuYFS/tvsWsaf4q/9Id3UF43KBhOg+p2scWQ/tmc6fl+DrR8QZiIycImEigMEDIGDIkQ/fTonsbEXeJ9pFlYWiNO9FBwM3tVMcWKrcrdjqmS87zIHA1wI6hOlRFCSpYOz5Tenqd0QV/X77yHmSSuI0oRJlR/+bdC+Rju4MgwY1fRQa4MtYZvJNSUmVHU9yu/gD5sFXnv40zPOvXK89cMOPv/bHXi1XBa1qSRLSoMYKYYkDyIjDbgOHe0= ubuntu@ip-172–31–45–133
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: First, exit from the .ssh directory using the below-given command:
cd .ssh
Go to the “assignment4” directory using the below-given command:
cd assignment4
Go to the “Git” machine. Put this URL to push the branch in the “Git-Assignment-4” repository.
Run the below-given command:
git push Git-Assignment-4 master
Press “enter” from the keyboard & “master” repo will be successfully pushed to the “Git-Assignment-4” repository.
Step 26: Go to “Github Repository: Git-Assignment-4” & refresh the browser.
A message will be shown as “master has recent pushes (1 minute ago)”.
Step 27: Go to “master” & “master.txt” will be displayed here.
Step 28: In the “Github repository”, “main” is a default file, which can’t be deleted due to the “default” branch.
So, we will now make the “master” branch our “default” branch.
Click on “Settings”.
Step 29: Click on the “Arrow” sign.
Step 30: Choose “master” here & click on “update”.
Step 31: Click “I understand, update the default branch”.
Step 32: Now, “master” has been a “default” branch which can’t be deleted until “default” status.
Step 33: Click on “ode”.
Step 34: Click on “2 Branches”.
Step 35: Click on the “delete” option.
Step 36: The “main” branch will be successfully deleted & now “master” as a default branch will be shown.
Step 37: Now, only one branch will be shown here.
Problem (2) Solution: Create 3 branches: public 1, public 2 and private
Step 1: Now, we will create the three branches such as “public1”, “public2” & “private”.
Use the below-given command:
git branch public1
git branch public2
git branch private
Now, we will run the below-given command to determine how many branches are created.
git branch
All the branches (public1, public2, private) will be successfully created
Step 2: Push all the repository to Git Hub Account using the below-given command:
git push Git-Assignment-4 public1 public2 private
All branches will be successfully pushed to the “Git-Assignment-4” repository.
Step 3: Go to “Github Repository”, all branches will be successfully pushed.
Problem (3) Solution: Put public1.txt on public 1 branch, stage, and commit
Step 1: First, we will go inside the “public” branch using the below-given command:
git checkout public1
Step 2: Create a “public.txt” file using the below-given command:
touch public.txt
Run the below-given command & the “public.txt” will be successfully created:
ls
Step 3: Stage the “public.txt” file using the below-given command:
git add public.txt
Step 4: Commit the “public.txt” file using the below-given command:
git commit -m "committing master.txt"
The file (public.txt) will be successfully committed.
Problem (4) Solution: Merge public 1 on the master branch
Step 1: Go to the “master” branch using the below-given command:
git checkout master
Step 2: Merge the “public1” branch with “master” using the below-given command:
Step 2: Merge the “public1” branch with “master” using the below-given command:
git merge public1
The “public1” branch will be successfully merged.
Problem (5) Solution: Merge public 2 on the master branch
Step 1: Use the below-given command to merge the “public2” branch with the “master” branch:
git merge public2
The “public2” will be successfully merged with the “master” branch.
Problem (6) Solution: Edit master.txt on a private branch, stage, and commit
Step 1: Go to “private” using the below-given command:
git checkout private
Step 2: Use the below-given command to edit the file:
nano master.txt
Step 3: Write some content here such as: “New Edits in master.txt file”.
Step 4: Run the below-given command to check the “master.txt” status:
git status
Step 5: Stage the “master.txt” file using the below-given command:
The file will be successfully staged.
Step 6: Run the below-given command to commit the “master.txt” file using this command:
git commit –m "commit master.txt"
Step 7: Push All the changes to the “Git-Assignment-4” repository using the below-given command:
git push -u -f Git-Assignment-4
All changes have been successfully pushed to the private branch in the “Git-Assignment-4” repository.
Here, the new “master.txt” code of the “private” branch will be updated in the “public1” & “public2” branches.
Problem (7) Solution: Now update branch public 1 and public 2 with new master code in private
Step 1: Go to the “public1” branch using the below-given command:
git checkout public1
Step 2: Run the below-given command to merge the “private” branch with “public1”:
git merge private
Step 3: A message will be shown like the below image.
Do “CTRL+X” to exit from the file.
Step 4: The “private” branch will be successfully merged with the “public1” branch.
Step 5: Run the below-given command to update the local repository using this command:
git push –u Git-Assignment-4
The code will be successfully updated in “master.txt” in “public1” in the “Git-Assignment-4” repository.
Step 6: Again, go to the “public2” branch using the below-given command:
git checkout public2
You will successfully land inside the “public2” directory.
Step 7: Merge the “private” branch to “public2” using the below-given command:
git merge private
The “private” branch will be successfully merged with the “public2” branch.
Step 8 Run the below-given command to update the local repository using this command:
git push –u Git-Assignment-4
The code will be successfully updated in “master.txt” in “public2” in the “Git-Assignment-4” repository.
Problem (8) Solution: Also update the new master code on the master
Step 1: Go to the “master” branch using the below-given command:
git checkout master
Step 2: Run the below-given command to merge the “private” branch with “master”:
git merge private
Step 3: A message will be shown like the below image.
Do “CTRL+X” to exit from the file.
Step 4: The “private” branch will be successfully merged with the “master” branch.
Step 5: Run the below-given command to update the local repository using the below-given command:
git push –u Git-Assignment-4
The code will be successfully updated in “master.txt” in the “master” branch in the “Git-Assignment-4” repository.
Problem (9) Solution: Finally update all the code on the private branch
Step 1: Go to the “private” branch using the below-given command:
git checkout private
Step 2: Merge “public1” with the “private” branch using the below-given command:
git merge public1
Step 3: Run the below-given command to change into the “Git-Assignment-4” repository on “Git Hub”.
Step 4: Now, all the codes have been successfully updated to the “private” branch.
The “public.txt” has no content to show here.
Check these Git Case Assignment & Studies Also:
Create a Git Workflow Architecture & Use Hotfix to Push a File — Git Assignment 5
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