Introduction
This is a very simple blog where I’ll tell you how to add an existing project to GitHub or any Git repository.
I have a simple JSP Hello-World project in my local system and I would add this project to GitHub.
Prerequisite
- I assume that you already have installed git utility in your system. If not install after downloading it from https://git-scm.com/download/win
- If you don’t already have it, head to https://github.com and sign up.
Setup local Git repo
- Traverse to the project location. This location contains all my project artefacts:


- Now, we will initialize this directory as a git repository using following command. This will initialize an empty git repository.
1 |
git init |
- Next, we will add all the files to the newly created local repository by issuing following command
1 |
git add . |
- After this is done, we’ll check the status of the activities so far by issuing following command. In the screen grab below, notice that all the project files have been added to the repo. But these files are yet to be committed.
1 |
git status |

- Let’s commit the project artefacts to the local repository by using following command
1 |
git commit -m "initial commit of my hello world JSP project" |
Now, observe the result. If it’s your very first encounter with git from local system, you may see something similar following result. This is because, there is no default identity setup yet.

- Now, we will run above two commands to set the identity
1 |
git config --global user.email "PROVIDE_YOUR_EMAIL_ID_HERE"<br>git config --global user.name "PROVIDE_YOUR_NAME_HERE" |
- Once the identity is setup, let’s run the commit command again and observe the result

Create GitHub Repo & Setup locally
- Login using your credential and create a repo. I have created a repository called HellWorld

- Thereafter, Copy the git repo URL from github by clicking on the highlighted icon or just select/copy

- Now, let’s the following command. The highlighted URL is the URL of your repo. [Don’t just copy paste the below URL 😉]
1 |
git remote add origin <strong><em><span style="color:#cf2e2e" class="has-inline-color">https://github.com/msadrud/HelloWorld.git</span></em></strong> |
Push existing local project to Github
- Next, we will push the already committed code to remote git repo (in master branch) that we just created above by issuing following command
1 |
git push origin master |

- When you issue this command, it will (if you have not already logged in using git bash) popup a window to login to your account. Please provide your account details and login.
- Once successfully done, it will upload all your project data from local repo to remote github repo

Conclusion
Well, this is the end of this tutorial. You just learnt how to add an existing project to GitHub or any Git repository.