VOOZH about

URL: https://www.digitalocean.com/community/tutorials/how-to-push-an-existing-project-to-github?comment=205188

⇱ How to Push an Existing Project to GitHub | DigitalOcean


How to Push an Existing Project to GitHub

Updated on October 8, 2025
👁 How to Push an Existing Project to GitHub

Introduction

GitHub is a cloud-hosted Git management tool. Git is distributed version control, meaning the entire repository and history lives wherever you put it. People tend to use GitHub in their business or development workflow as a managed hosting solution for backups of their repositories. GitHub takes this even further by letting you connect with coworkers, friends, organizations, and more.

In this tutorial, you will learn how to take an existing project you are working on and push it so it also exists on GitHub.

Key Takeaways

  • Initialize Git Locally for Version Control: Before pushing your project to GitHub, always initialize a Git repository in your local project folder using git init. This step creates the foundation for tracking changes, collaborating with others, and leveraging the full power of distributed version control. Proper initialization ensures your project history is preserved and ready for seamless integration with GitHub’s cloud-based platform.

  • Leverage .gitignore for Security and Clean Repos: Utilize a .gitignore file to exclude sensitive data, configuration files, and unnecessary system artifacts from your repository. This best practice protects credentials, reduces clutter, and keeps your GitHub repo professional and secure. A well-crafted .gitignore is essential for compliance, privacy, and maintaining a clean codebase, especially when collaborating or deploying to production.

  • Choose SSH or HTTPS Authentication Wisely: For frequent GitHub interactions, SSH authentication is highly recommended due to its enhanced security and convenience—once set up, you won’t need to re-enter credentials. HTTPS is simpler to configure and ideal for occasional use or restricted environments. Selecting the right authentication method streamlines your workflow and safeguards your code, aligning with industry best practices.

  • Push Projects Using CLI, VS Code, or GitHub Desktop: You can push your code to GitHub using the command line interface (CLI) for maximum control and reliability, or opt for graphical tools like Visual Studio Code and GitHub Desktop for a more intuitive experience. Each method supports essential Git operations—staging, committing, and pushing—so you can choose the workflow that best matches your comfort level and project needs.

  • Expand Workflows with GitHub MCP Server and AI Tools: Integrate GitHub MCP Server to connect advanced AI assistants (such as Claude, Cursor, or VS Code Copilot Chat) directly to your repositories. This enables natural language commands for pushing code, managing pull requests, and automating tasks, making your development process smarter and more efficient. Embracing AI-powered workflows future-proofs your projects and maximizes productivity.

How to Push an Existing Project to GitHub

  1. Create a new GitHub Repo
  2. Initialize Git in the Project Folder
  3. Initialize the Git Repo

Deploy your applications from GitHub using DigitalOcean App Platform. Let DigitalOcean focus on scaling your app.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author(s)

👁 Nicholas Cerminara
Nicholas Cerminara
Author
👁 Bradley Kouchi
Bradley Kouchi
Editor
👁 Vinayak Baranwal
Vinayak Baranwal
Editor
Technical Writer II
See author profile

Building future-ready infrastructure with Linux, Cloud, and DevOps. Full Stack Developer & System Administrator. Technical Writer @ DigitalOcean | GitHub Contributor | Passionate about Docker, PostgreSQL, and Open Source | Exploring NLP & AI-TensorFlow | Nailed over 50+ deployments across production environments.

Category:
Tags:

Still looking for an answer?

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

It says this:

The authenticity of host ‘github.com (13.234.210.38)’ can’t be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added ‘github.com’ (ED25519) to the list of known hosts. git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

Thanks for the article - its a great writeup to address this common issue. For this to work for me, at least using https github repo paths, I had to add

git branch -M main

after adding my commit message.

This comment has been deleted

I ran into the following issue when working through this, which required me to set up my SSH keys between my local workstation and the github account. Since I tend to use specific SSH keys for different purposes, there is a little more work to do; I’ll show both standard (using default SSH keys) and extended (using specific SSH keys) approaches here.

NB: Do this before you attempt to Push to Github or if you get the following error:

% git push -v -u -f origin main 
Pushing to github.com:github_username/github_repository.git
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Standard approach

This uses the default SSH keys for the user account in question. The drawback (in my opinion and scenario) is that my default SSH keys typically have passphrases which I don’t want to include for my CI/CD pipelines.

  1. Generate the ssh key without a passphrase; you may include one, if you wish, but bear in mind you will be prompted for this each time you run a command that needs to access the remote repository
% ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/bigdev/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): <<Enter a passphrase if required>>
Enter same passphrase again: <<Re-Enter a passphrase if required>>
Your identification has been saved in /Users/bigdev/.ssh/id_rsa
Your public key has been saved in /Users/bigdev/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:Rx349489384djasdfJD+ywf3M3q3R52wJ3qJ2KjILN0OZ0Q90 bigdev@tintin.local
The key's randomart image is:
+---[RSA 3072]----+
| ..o o+ .o |
| *C+o +... o|
| ..@.. + |
| .........|
| . 0D8s o |
| . + o. . ooB|
| **=--.. =O|
| . = =+oBB .+|
| ..oo .. 0.|
+----[SHA256]-----+

Extended approach

This uses a specific SSH key dedicated to this function; may be reused for others if needed. The advatage (in my opinion and scenario) is that it separates the keys used for standard activities and these dedicated SSH keys typically can exclude passphrases making my CI/CD smoother (IMHO).

  1. Generate the ssh key without a passphrase; you may include one, if you wish, but bear in mind you will be prompted for this each time you run a command that needs to access the remote repository
% ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/bigdev/.ssh/id_rsa): /Users/bigdev/.ssh/id_rsa_github # Note we have specified a specific filename here!
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/bigdev/.ssh/id_rsa_github
Your public key has been saved in /Users/bigdev/.ssh/id_rsa_github.pub
The key fingerprint is:
SHA256:Rx349489384djasdfJD+ywf3M3q3R52wJ3qJ2KjILN0OZ0Q90 bigdev@tintin.local
The key's randomart image is:
+---[RSA 3072]----+
| ..o o+ .o |
| *C+o +... o|
| ..@.. + |
| .........|
| . 0D8s o |
| . + o. . ooB|
| **=--.. =O|
| . = =+oBB .+|
| ..oo .. 0.|
+----[SHA256]-----+
  1. Add a config to enable to use of the specific ssh key when invoking commands for github
  • Edit the file ~/.ssh/config as below
Host github.com
 Hostname github.com
 User git
 IdentityFile /Users/bigdev/.ssh/id_rsa_github
 IdentitiesOnly yes

#Final step

Copy the content of the .pub file created and add this to the GitHub settings.

  • Navigate to Settings > SSH and GPG keys > New SSH key
  • Enter a title / name for the key, any informative name will do, this is just a label
  • In the Key textbox, paste the content from the chosen .pub file
  • Click on Add SSH key

That’s it, you’re all set!.

This otherwise good tutorial leaves out security steps. Here, the github repo is used as a remote repository. An alternative is to treat it as an https site and use a PAT (Personal Access Token).

To set up a PAT, log into github and go to settings --> developer settings --> personal access tokens (classic). For permissions, I chose to click all in the repo category and all in the user category. You should probably check a good tutorial on PATs if you want to know more about the other permissions. With these two, I was able to push my project to the new github repo.

In the CLI instructions, replace git remote add origin git@github.com:sammy/my-new-project.git with git remote add origin https://github.com/sammy/my-new-project.git

とても、ためになりました。ありがとうございます!

👁 Creative Commons
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
  • Deploy on DigitalOcean

    Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and AI-native businesses

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

© 2026 DigitalOcean, LLC.Sitemap.
Dark mode is coming soon.