In daily basis developer work is to do code check in, check out, pull, fetch and so on. But in the current post, we will learn how to push the existing local project to GitHub repository.
For example:- I have a project EmployeeManagement(EMS) in my local but no one can able to access or modify code without creating and pushing code to GitHub repository.
The steps to push local project to GitHub repository 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.
For example:- I have a project EmployeeManagement(EMS) in my local but no one can able to access or modify code without creating and pushing code to GitHub repository.
The steps to push local project to GitHub repository 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 errors, do not initialize the new repository with README,
license, or gitignore files. You can add these files after your project has been pushed to GitHub.
Click on Button/action ""Create repository"
2) Initialize the local directory as a Git repository.
Change the current working directory to your local project and then initialize the local directory as a git repository using command "git init"
e.g your project directory is C:\\ProjectRepo\EMS
then
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 each file, then use git add "file path"
C:\ProjectRepo\EMS>git add "file path to add to git"
# Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.
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