How to Add a Local Repository to a GitHub Repository
If you’ve just created a project and want to push it to a GitHub repository, follow these simple steps:
Steps to Push a Local Repo to GitHub
Initialize Git in your project folder:
git initStage all the files for the first commit:
git add .Commit your changes:
git commit -m "Initial commit"Verify that you are on the
mainbranch:git branchAdd the GitHub repository link:
git remote add origin {your-repo-link}Push the changes to the
mainbranch:git push origin main
Handling Authentication Issues
If you encounter an authentication error while pushing (due to token issues):
Remove the old origin:
git remote rm originCreate a personal access token:
Go to GitHub > Settings > Developer Settings > Personal Access Tokens > Tokens (classic)
Generate a new token and select permissions like
repo,admin:repo_hook, anddelete_repo.
Add the remote repository again using your token:
git remote add origin https://<TOKEN>@github.com/{USERNAME}/{REPO_NAME}.gitPush again:
git push origin main
And that's it! Your local project should now be successfully pushed to GitHub.