Adding New Project To The GitHub Repository

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",
 
Adding New Project to The GitHub Repository 
 
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".
 
Adding New Project to The GitHub Repository
 
That's all. Now you have created a "GitHub Repository".
 
Step 1
 
Open Git Bash.
 
Adding New Project to The GitHub Repository
 
Step 2
 
Change the current working directory to your local project path.
 
Step 3
 
Initialize the local directory as a Git repository.
  1. $ git init   
Step 4
 
Add the files to your new local repository. This stages them for the first commit.
  1. $ git add .  
  2. # 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.
  1. $ git commit -m "Initial Commit"  
  2. # 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)
 
Adding New Project to The GitHub Repository 
 
Step 7
 
In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
  1. $ git remote add origin remote-repository-url   
  2. # Sets the new remote   
{To change the existing remote repository}
  1. $ git remote set-url origin remote-repository-url  
  2. $ git remote -v  
  3. # Verifies the new remote URL  
Step 8
 
Push the changes in your local repository to GitHub.
  1. $ git push origin master --force  
  2. # 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.