Let us see how to add a new project from the local machine to the GitHub Repository.
At first, we will create a new repository on
GitHub.
Go
here and log in with your credentials.
Click on "New",
To avoid errors, do not initialize the new repository with README.md, license, or gitignore files. You can add these files after your project has been pushed to GitHub.
Give some name to your repository on the "Repository name" and click on "Create repository".
That's all. Now you have created a "GitHub Repository".
Step 1
Open Git Bash.
Step 2
Change the current working directory to your local project path.
Step 3
Initialize the local directory as a Git repository.
Step 4
Add the files to your new local repository. This stages them for the first commit.
- $ git add .
- # Adds the files in the local repository and stages them for commit.
Step 5
Commit the files that you've staged in your local repository.
- $ git commit -m "Initial Commit"
- # Commits the tracked changes and prepares them to be pushed to a remote repository.
Step 6
At the top of your GitHub repository, click on the dropdown "Code" and copy the "URL" (remote-repository-url)
Step 7
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
- # Sets the new remote
{To change the existing remote repository}
- $ git remote set-url origin remote-repository-url
- $ git remote -v
- # Verifies the new remote URL
Step 8
Push the changes in your local repository to GitHub.
- $ git push origin master --force
- # Pushes the changes in your local repository up to the remote repository you specified as the origin.
Step 9
Check out your GitHub Repository.
Now you have successfully pushed your local project changes to your GitHub Repository.
Conclusion
In this blog, we learned a step by step way to add an existing/new project from the local machine to the remote GitHub Repository.