How to Add a Local Repository to a GitHub Repository
Published on Saturday, Aug 17, 2024
1 min read
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 init
-
Stage all the files for the first commit:
git add .
-
Commit your changes:
git commit -m "Initial commit"
-
Verify that you are on the
main
branch:git branch
-
Add the GitHub repository link:
git remote add origin {your-repo-link}
-
Push the changes to the
main
branch: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 origin
-
Create 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}.git
-
Push again:
git push origin main
And that's it! Your local project should now be successfully pushed to GitHub.
- Tags :
- #GitHub