Day 4: Push existing project to existing Git repo
Ninan Kara
Posted on September 25, 2020
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 :)
Posted on September 25, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.