DEV Community

Cover image for Creating an Index File in Git Bash and Push it to GitHub
Wisdom Iyayinosa Bezaleel
Wisdom Iyayinosa Bezaleel

Posted on • Updated on

Creating an Index File in Git Bash and Push it to GitHub

In this blog, i will take you on a step-by-step journey to master the art of creating index files using a command-line interface on Git Bash. I will also take you through the process of pushing your codes to GitHub

Prerequisite
Ensure you have installed Git Bash on your
Ensure you have created a GitHub account

So lets get started.
First thing we do is to configure your environment, that is to ensure you are logged into your GitHub account.
Open your Git Bash and input these commands, remember always to press ENTER after every command line.

git config --global user.name
git config --global user.email

Image description
Now we have to create our Folder/Directory. To do this, input the command mkdir, leave a space and give it a name. mkdir means make a directory. "mkdir basefaculty"
Input the command "cd (your directory)" and press enter to open your directory

Image description
Input the command "git init" and press enter

This command creates a new Git repository in the current working directory.

Image description
You are good to go.
Now we have to create our file and input our code. we are going to create a new empty Text file named index.html.

Input the command "touch index.html" and press enter.

Image description
To input code in the empty file, input the command vi

A blank space will appear, Click on the letter "i" on your keyboard to edit the file. Right-click and click on paste, to input your code. Let us use this code below as test. Copy this code from the comment section of this blog, and paste this in the blank page.
<!DOCTYPE html>


My web page


Hello, world!


This is my first web page.


It contains a
main heading and paragraph .



Image description
To continue, press the esc button on your PC, input :wq and press enter to close the index.html file

Image description
To view your code, input the command cat

Image description
Now we will need a repository to house this folder and file, let's quickly create one by going to our GitHub account. To create our repository, login to your GitHub account.
On the upper-left corner of your account, click on the + sign and select "New repository"

Image description
Give your repo a name, ensure its public, and tick the "Add a ReadME file" box

Image description
Click create to finalize.

Image description
On your repository page, click on "Code", copy the url on the HTTPs section, and go back to your Git Bash
Image description
We are done creating our repository, now lets go back to our Git Bash and push.
To add a remote repository named "origin" with a specified link to your Git repository, you can use the "git remote add origin" command followed by the remote name ("origin") and the URL of the remote repository.

git remote add origin

Image description

To add the file input "git add index.html" and enter

Image description
You can confirm if the file has been added by inputting this command.
git status
you should get this feedback
Image description
Input this command to create a new commit in your Git repository with a commit message
git commit -m <'the message'>

Image description
You can check the status by inputting the "git status" command

Image description

Now input the command 'git push origin master' and press enter. This command pushes the commits from your local "master" branch to the remote repository specified by the remote name "origin". After executing the push command, Git will upload your local commits to the GitHub repository in your master branch as shown in the generated command.

Image description
On your repository, on the code section, you would notice the default branch is main. To view your index.html file, click on branch and select the master branch.
Image description
From the capture below, you can see that our index file and our commit message reflect here.
Image description
Click on the text index to see the code we deployed

Image description

There you have it, Hopefully this helps.

Top comments (1)

Collapse
 
thereal_bezali profile image
Wisdom Iyayinosa Bezaleel

Copy and paste this link on the blank page

<!DOCTYPE html>





My web page





Hello, world!



This is my first web page.



It contains a

main heading and paragraph .