DEV Community

Cover image for How to Create an Index file in Gitbash and Push it to Gitgub
joseph4real
joseph4real

Posted on

How to Create an Index file in Gitbash and Push it to Gitgub

In this blog I will be using Gitbash, a command line interface to create an in-index html file and push it to the githup repository.

Configure your environment
a. Enter this command: git config –global user.name , press enter.
b. Enter also: git config –global user.email , press enter.

Image description

Make directory/ Create a folder
c. Make and change into the directory by Input the command below:
mkdir joseweb and cd joeweb.

Image description
d. Initialize your new git repo in the working directory you created above using the this command: git init.

Image description
e. Create an html file (index.html) by inputing this command:
Touch index.html

Image description

f. Input code into the html file using this command: vi
A blank space will be opened, right click and paste your html code into the git blank space, continue by pressing escape key., and: wq to save and close the index.html file.

Image description
h. View you code by typing this command: cat ..

Image description

Create the Repository in github
You will need to create a repo to house your file using you github account
a. On the githuB page click on create new repo.

Image description
b. Enter the repository name, give theit a description, select public, initialize by checking add a README file, then click on create repository.

Image description
c. On the repo page, click on Code and copy link under HTTPS.

Image description
d. After successfully creating the repository, copy the HTTPs URL into the Gitbash.

Push to Github
a. To add the repo created in the githug into the gitbas we use the command: git remote add origin, followed by the remote name (origin) and the URL:
Git remote add origin

Image description

Image description
b. Add the index file and press enter with this command: Git add index.html. type git status to check if the html file has been added.

Image description
c. Create a new commit in your git repo with a commit message using this command git commit -m . Check again by using git status.

Image description
d. You can then use this command git push origin master to push the commit from the local master branch (i.e. index file from your loacal system) to the remote repo (githup repo) being specified by the name origin.

Image description

On the execution of the command above, your loacal commit (index file) will be uploaded to the github repo in your master as shown in the generated result above.
e. On your githb repo, “you will see master had recently been pushed” i.e. the commit you just push, see main as default branch. Select master and you will be able to view the index.html you pushed.

Image description

NOTE: The capture above shows the index.html file and the commit message inputted from gitbash, this shows file was successfully pushed to repo.
f. Open the index.html to verify the content.

Image description

Conclusion:-The blog shows that the web contents (html code) has successfully been pushed from gitbash command line interface to the github repository.

Top comments (0)