Skip to main content

Command Palette

Search for a command to run...

How to Add a Local Repository to a GitHub Repository

Updated
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

  1. Initialize Git in your project folder:

     git init
    
  2. Stage all the files for the first commit:

     git add .
    
  3. Commit your changes:

     git commit -m "Initial commit"
    
  4. Verify that you are on the main branch:

     git branch
    
  5. Add the GitHub repository link:

     git remote add origin {your-repo-link}
    
  6. 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):

  1. Remove the old origin:

     git remote rm origin
    
  2. 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, and delete_repo.

  3. Add the remote repository again using your token:

     git remote add origin https://<TOKEN>@github.com/{USERNAME}/{REPO_NAME}.git
    
  4. Push again:

    git push origin main
    

And that's it! Your local project should now be successfully pushed to GitHub.

More from this blog