DEV Community

Ninan Kara
Ninan Kara

Posted on

4

Day 4: Push existing project to existing Git repo

Intro

Which one is first? Create new project in local? Create repository in local? or create repository in cloud first? Whatever the sequence, the process of connecting our project to git might be different. Honestly it is easier to generate repository in cloud first (Github, Gitlab, etc), then clone it to local. And modify the project afterward. But, sometimes I forgot. I create the project first, and also generate the repository in cloud.

So, how to connect existing project to existing repository?
Here it is.

Step-by-step

Note: I use VSCode and Gitlab

git init
git add .
git commit -m "initial commit"
git remote add origin your-git.git
git remote -v //to confirm
git branch --set-upstream-to=origin/master master
git pull --allow-unrelated-histories
git push

Voila.. its connected now :)

Conclusion

Previously, I always delete the local project, then clone the cloud repo to local. This is okay, but what if the project is already big? You may not want to redo it from scratch. Another way is to push directly and create new project in cloud, but I am too lazy to delete the old one and create the new one. Because I want to reserve the project name (so I need to delete the old one).

So, for now one, if I forgot to clone the repo first, I prefer this way to connect both. And wrote it here, since I keep forgetting stuffs :)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more