How To Git Push An Existing Project To GitHub - The Server Side

Proper steps to add existing code to GitHub

The proper way to push a new project into an existing GitHub repository follows these steps:

  1. Create a GitHub repository for the existing project.
  2. Copy the GitHub URL for the new repo to the clipboard.
  3. Perform a git init command in the root folder of the existing project.
  4. Add all of the existing project’s files to the Git index and then commit.
  5. Add the GitHub repo as a remote reference for the existing project.
  6. Perform a git push operation with the -u and -f switches.
  7. Verify that the existing project’s files have been pushed to GitHub.

How to push code to GitHub

Many certified DevOps engineers and professional solutions architects only want to know the Git commands necessary to push their existing project to GitHub.

Git, GitHub & GitHub Copilot Certification Made Easy

Want to get certified on the most popular AI, ML & DevOps technologies of the day? These five resources will help you get GitHub certified in a hurry.

  • Master vibe coding and prove it with the GitHub Copilot certification
  • Prove you know how CI/CD with the GitHub Action certification
  • Prove you know your way around Git and GitHub with the GitHub Foundation certification.
  • Show you know how to work on a team with a Scrum Master cert or Product Owner credential
  • Let employers know you understand LLMs and Agentic AI with a GCP AI Leader certification

Get certified in the latest AI, ML and DevOps technologies. Advance your career today.

To save those readers from going through the entire example, here are the Git commands used in this tutorial. These commands assume a push to a GitHub repo named existing-website, owned by a GitHub user named cameronmcnz:

  • git init
  • git add .
  • git commit -m "Add existing project files to Git"
  • git remote add origin https://github.com/cameronmcnz/example-website.git
  • git push -u -f origin master

Updating a remote GitHub repo

To push an existing project to GitHub, you must first create a GitHub repository. To do this, simply click the green “Create repository” button in GitHub’s online console and provide a repository name.

For this example, we will name the repository example-website.

GitHub repo for existing project

You must create a GitHub repo to manage your existing project’s files.

Obtain the repo’s GitHub URL

After you create the repository, click the green “Code” button. This reveals the GitHub URL for HTTPS connections.

Copy this value for use in a future step.

find GitHub URL

The GitHub URL is used to push the existing project to GitHub.

Initialize Git in the existing project

If the existing project does not already use Git, issue a git init command in the root folder. After the repository is initialized, add all of the project files to the Git index and perform a commit:

git add . git commit -m "Add existing project files prior to the push to GitHub."

Add a remote reference for GitHub

To let your existing project synchronize with GitHub, issue a git remote add command to configure a reference from you local Git installation to the repository on GitHub. Note that the last segment of the git remote add command is your project’s GitHub URL.

git remote add origin https://github.com/cameronmcnz/example-website.git

Push the first commit to GitHub

Once you’ve added the remote reference, you are ready to push your existing project to GitHub.

Simply issue a git push command with the name of the current branch along with the -u and -f switches.

Note that older Git repositories create a master branch by default, while newer ones use main. Amend the git push command accordingly.

git push -u -f origin master

The -u switch makes the remote GitHub repo the default for your existing project. The -f switch forces Git to overwrite any files that already exist on GitHub with your existing project’s files.

Verify the GitHub push

To verify that the existing project was pushed to GitHub successfully, log into the GitHub website and browse the repository. All of the files from your existing project should be visible on GitHub.

And that’s how easy it is to push an existing project to a Git or GitHub repository.

Cameron McKenzie

Cameron McKenzie is an AWS Certified AI Practitioner, Machine Learning Engineer, Solutions Architect and author of many popular books in the software development and Cloud Computing space. His growing YouTube channel training devs in Java, Spring, AI and ML has well over 30,000 subscribers.

Next Steps

AWS Solutions Architect Book

The AWS Solutions Architect Book of Exam Questions by Cameron McKenzie

So what’s next? A great way to secure your employment or even open the door to new opportunities is to get certified. If you’re interested in AWS products, here are a few great resources to help you get Cloud Practitioner, Solution Architect, Machine Learning and DevOps certified from AWS:

  • AWS Certified Cloud Practitioner Book of Exam Questions
  • AWS Certified Developer Associate Book of Exam Questions
  • AWS Certified AI Practitioner Book of Exam Questions & Answers
  • AWS Certified Machine Learning Associate Book of Exam Questions
  • AWS Certified DevOps Professional Book of Exam Questions
  • AWS Certified Data Engineer Associate Book of Exam Questions
  • AWS Certified Solutions Architect Associate Book of Exam Questions

Put your career on overdrive and get AWS certified today!

Tag » How To Push In Github