Neo Music Neo Music - 1 month ago 6
Git Question

Push new local project to exsiting remote Git

I create a Git repo and pushed few commits to GitHub. Then I download this project manually (instead of using

git clone
). I started working like with new project. Now I want to push this local project to my existing remote repository. How can I do it?

Answer

If the version that you manually downloaded includes a .git folder, then the solution is simple:

# add / commit if necessary first
git remote add origin <github url>
git push origin master

However, my understanding is that GitHub's zip files don't include the .git folder, which I assume is what you meant by "manually downloaded".

If you don't have the .git folder:

  1. Switch to the "real" local Git repo. (If your original repo was on another machine, then clone a new one from GitHub.)

  2. Copy all the files from your manually-downloaded version to your local repo.

  3. Add and commit:

    git add .
    git commit -m "Foo the bar because baz"
    

    (You can also split the changes into multiple commits by git adding specific files, and/or using git add --patch.)

  4. Push:

    git push origin master
    

In the future, it's generally better to clone the repo rather than downloading a zip file of its contents. Since Git commits are local by default, you can even make many commits locally without affecting anything on the server.