Create The Files & Push them to Git Hub Repository — Git Assignment 1
Tasks to Be Performed:
1. Based on what you have learned in the class, do the following steps:
a. Create a new folder
b. Put the following files in the folder
● Code.txt
● Log.txt
● Output.txt
c. Stage the Code.txt and Output.txt files
d. Commit them
e. And finally push them to GitHub
2. Please share the commands for the above points.
For copying the commands or viewing the files, check the given Git Hub Repository:
Problem (1) Solution: Based on what you have learnt in the class, do the following steps:
a. Create a new folder
b. Put the following files in the folder
● Code.txt
● Log.txt
● Output.txt
A. Create a New Folder (assignment1)
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-0bc525cdc20d5267d)”.
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.
Step 15: Create a new folder named “assignment1” using the below-given command:
mkdir assignment1
ls
A folder will be successfully created named “assignment1”.
Do “ls” here & “assignment1” folder will be saved.
Step 16: To enter the “assignment1” folder, type the below-given command:
cd assignment1
You will be successfully landed inside the “assignment1” folder.
b. Put the following files in the folder
● Code.txt
● Log.txt
● Output.txt
Step 1: Use the below-given command to create these files:
touch Code.txt Log.txt Output.txt
ls
Do “ls” here & all the files will be successfully shown here.
c. Stage the Code.txt and Output.txt files
Step 1: Initialize the Git using the below-given command:
git init
Step 2: Now, stage both the files Code.txt & Output.txt using the below-given command:
git add Code.txt Output.txt
Step 3: To check which file is staged or not, use the below-given command:
git status
D. Commit them
Step 1: Now, we will commit both files using the below-given command:
git commit –m "Commit both Code.txt and Output.txt files"
Both files will be successfully committed.
E. And finally push them to GitHub
Step 1: First, type “github.com” in the “browser search address bar”.
Click on “Sign in” here.
Step 2: Sign in with your “email address” & “password” here.
Step 3: Click on “New” in “Top Repositories”.
Step 4: Choose the following options during the “Git Hub Repository Creation”.
Repository name: Git-Assignment-1
Description: Git Hub Assignment 1 (Basic Assignment)
Remain “Public” option enabled.
Choose “Add a README file” in “Initialize the repository with”.
Click on “Create repository”.
Step 5: The Repository named “Git-Assignment-1” has been successfully created.
Step 6: Now, go to the “Git” machine & use the below-given command to add “Repository URL”:
git remote add Git-Assignment-1 https://github.com/visaltyagi/Git-Assignment-1.git
The repository (Git-Assignment-1) will be successfully added.
Step 7: To check whether the GitHub Repository will be added or not, use the below-given command:
git remote –v
It will show the repository URL here.
Step 8: Run the below-given command to check how many branches are in the “Git hub repository”.
git branch
Step 9: Go to “Git Hub Profile” & click on “Settings” here to create the access token. The access token will be used when you push the branch to the “Git Hub Repository”.
Step 10: Click on “Developer Settings” at the end.
Step 11: Click on “Personal Access tokens > Tokens (classic)”.
Step 12: Click on “Generate new token > Generate new token (classic)”.
Step 13: Choose “Note” as “Access Token”. While, in “Select scopes”, choose the “repo” option.
Step 14: Click on “Generate token”.
Step 15: The token will be successfully generated. Please copy & paste this token into a separate notepad & save it. Otherwise, every time you have to generate a new token.
Copy the token by clicking on the icon.
Step 16: Go to the “Git” machine. Put this URL to push the branch in the “Git-Assignment-1” repository.
URL: git push Git-Assignment-1 master
Username: visaltyagi12
Password: Personal Access Token here
Press “enter” from the keyboard & “master” repo will be successfully pushed to the “Git-Assignment-1” repository.
Step 17: Go to “Github Repository: Git-Assignment-1” & refresh the browser.
A message will be shown as “master has recent pushes (12 minutes ago)”.
Also, both files have been shown here.
It means both files have been successfully pushed to the “Git-Assignment-1” repository.
Step 18: 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 19: Click on the “Arrow” sign.
Step 20: Choose “master” here & click on “update”.
Step 21: Click on “I understand, update the default branch”.
Step 22: Now, “master” has been a “default” branch which can’t be deleted until “default” status.
Step 23: Click on “code”.
Step 24: Click on “2 Branches”.
Step 25: Click on the “delete” option.
Step 26: The “main” branch will be successfully deleted & now “master” as a default branch will be shown.
2. Please share the commands for the above points.
Step 1: Run the below-given command to get all the commands used in this assignment:
git history
Copy the commands & paste here:
· sudo apt-get update
· mkdir assignment1
· ls
· clear
· ls
· cd assignment1
· touch Code.txt Log.txt Output.txt
· ls
· git init
· git add Code.txt Output.txt
· git status
· git commit -m "Commit both Code.txt and Output.txt files"
· git remote add Git-Assignment-1 https://github.com/visaltyagi/Git-Assignment-1.git
· git init
· ls
· git init
· git remote add Git-Assignment-1 https://github.com/visaltyagi/Git-Assignment-1.git
· ls
· git remote -v
· cd assignment1
· ls
· git branch
· cd assignment1
· git push Git-Assignment-1 master
Checkout these Git Hub Assignments Solution Here:
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
Create a Git Workflow Architecture & Use Hotfix to Push a File — Git Assignment 5
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