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

Visal Tyagi
DevOps-Guides
Published in
9 min readMay 14, 2024

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:

Git-Assignment-1
Git-Assignment-1

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”.

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.

Instance Name
]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
Launch Instance

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

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.

Machine Updated Successfully
Machine Updated Successfully

Step 15: Create a new folder named “assignment1” using the below-given command:

mkdir assignment1
ls
Create assignment 1 directory
Create assignment 1 directory

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
Assignment 1 Folder Created
Assignment 1 Folder Created

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
Create the Files
Create the Files

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
Initialize the Git
Initialize the Git

Step 2: Now, stage both the files Code.txt & Output.txt using the below-given command:

git add Code.txt Output.txt
Stage or Add the Files to Git
Stage or Add the Files to Git

Step 3: To check which file is staged or not, use the below-given command:

git status
Files Status
Files 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"
Commit Both Files
Commit Both 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”.

Sign in to GitHub
Sign in to GitHub

Click on “Sign in” here.

Step 2: Sign in with your “email address” & “password” here.

Put an Email Id & Password Here
Put an Email Id & Password Here

Step 3: Click on “New” in “Top Repositories”.

Create New Repository
Create New Repository

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.

Put the Repository Name and Description Here
Put the Repository Name and Description Here

Choose “Add a README file” in “Initialize the repository with”.

Click on “Create repository”.

Add a README File & Create Repository
Add a README File & Create Repository

Step 5: The Repository named “Git-Assignment-1” has been successfully created.

Git-Assignment-1 Created
Git-Assignment-1 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
Repo Added on Local
Repo Added on Local

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
Repository Successfully Added on Local
Repository Successfully Added on Local

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 
Master Branch Shown
Master Branch Shown

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”.

Go to Settings
Go to Settings

Step 10: Click on “Developer Settings” at the end.

Go to Developer Settings
Go to Developer Settings

Step 11: Click on “Personal Access tokens > Tokens (classic)”.

Go to Token (classic)
Go to Token (classic)

Step 12: Click on “Generate new token > Generate new token (classic)”.

Generate New Token
Generate New Token

Step 13: Choose “Note” as “Access Token”. While, in “Select scopes”, choose the “repo” option.

Access Token Entry
Access Token Entry

Step 14: Click on “Generate token”.

Generate Token Here
Generate Token Here

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.

Copy the Token
Copy the Token

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.

Push the Master Branch to Remote
Push the Master Branch to Remote

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)”.

Master Successfully Pushed With Both Files
Master Successfully Pushed With Both Files

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”.

Go to Settings
Go to Settings

Step 19: Click on the “Arrow” sign.

Click on Arrow Sign
Click on the Arrow Sign

Step 20: Choose “master” here & click on “update”.

Update default as “master”
Update default as “master”

Step 21: Click on “I understand, update the default branch”.

Choose the option
Choose the option

Step 22: Now, “master” has been a “default” branch which can’t be deleted until “default” status.

master as a default branch
master as a default branch

Step 23: Click on “code”.

Go to Code Section
Go to Code Section

Step 24: Click on “2 Branches”.

Click “2 Branches”
Click “2 Branches”

Step 25: Click on the “delete” option.

main branch
main branch
Delete the main branch
Delete the main branch

Step 26: The “main” branch will be successfully deleted & now “master” as a default branch will be shown.

main branch deleted successfully
the main branch was deleted successfully
Git-Assignment-1
Master branch with Files

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
Check Commands History
Check Commands 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

--

--