As developers, we perform Git operations such as commit, checkout, pull, fetch, and push on a daily basis. In this post, we will learn how to push an existing local project to a GitHub repository.
1) Create a repository on GitHub.
Create a GitHub account if you don't have.
Then Go to Account --> Your repositories
Click on New as shown in below screenshot.
For example, suppose you have a project named EmployeeManagement (EMS) on your local machine. Until you create a GitHub repository and push the project to it, other developers cannot access, collaborate on, or modify the code.
The steps to push an existing local project to a GitHub repository are as follows:
1) Create a repository on GitHub.
Create a GitHub account if you don't have.
Then Go to Account --> Your repositories
Click on New as shown in below screenshot.
![]() |
| Github New Repo Creation |
When click on New button, will open Create New Repository page.
![]() |
| Create Repository |
Provide repository name(Usually project name)
Select public or private repository option
To avoid merge conflicts, do not initialize the new repository with a README, LICENSE, or .gitignore file. You can add these files after your project has been pushed to GitHub.
Click the Create repository button.
2) Initialize the local directory as a Git repository.
Change the current working directory to your local project, and then initialize it as a Git repository by running the
git init command.For example, if your project is located at C:\ProjectRepo\EMS, run the following commands:
C:\ProjectRepo\EMS>git init
3) Add the files in your new local repository(using git add command). This stages them for the first commit.
Add files to the GitHub,
C:\ProjectRepo\EMS>git add .
If you want to add a specific file instead of all files, use the following command:
C:\ProjectRepo\EMS>git add <file-path>
Adds files to the local repository and stages them for commit. To unstage a file, use the
git reset HEAD <file-name> command.4) Commit the files that you've staged in your local repository.
Use command - git commit -m "First commit" to commit the added file to gitHub.
C:\ProjectRepo\EMS>git commit -m "First commit"
5) At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.
Copy below HTTPS or SSH Project URL
![]() |
| Remote Repo HTTPS o SSH URL |
In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
>git remote add origin "remote repository URL"
6) Push the changes in your local repository to GitHub.
Using git push command, you can the committed files to the remote repository as follow,
master - is the branch name.
Related Post:--
Permission denied(publickey), fatal:couldn't read from remote repository - Gihub Error
>git remote add origin "remote repository URL"
C:\ProjectRepo\EMS>git remote add origin "remote repo HTTPS or SSH URL"
6) Push the changes in your local repository to GitHub.
Using git push command, you can the committed files to the remote repository as follow,
C:\ProjectRepo\EMS>git push origin master
master - is the branch name.
Related Post:--
Permission denied(publickey), fatal:couldn't read from remote repository - Gihub Error





