Add an existing project to GitHub or any Git repository

Add an existing project to GitHub or any Git repository

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

Setup local Git repo

  • Traverse to the project location. This location contains all my project artefacts:
Project Location in local system
Traverse to project location in local system
  • Now, we will initialize this directory as a git repository using following command. This will initialize an empty git repository.
  • Next, we will add all the files to the newly created local repository by issuing following command
  • 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.
git status result after adding all the files to the repo
  • Let’s commit the project artefacts to the local repository by using following command

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.

Set default identity
  • Now, we will run above two commands to set the identity
  • Once the identity is setup, let’s run the commit command again and observe the result
git commit successfully executed

Create GitHub Repo & Setup locally

  • Login using your credential and create a repo. I have created a repository called HellWorld
Create GitHub Repository
  • Thereafter, Copy the git repo URL from github by clicking on the highlighted icon or just select/copy
Copy Git Repo URL
  • Now, let’s the following command. The highlighted URL is the URL of your repo. [Don’t just copy paste the below URL 😉]

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
add existing project to github repo
  • 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
Files uploaded 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.

124

No Responses

Write a response

This site uses Akismet to reduce spam. Learn how your comment data is processed.