I have an existing Git repository on Github.
I wanted to reorganise my code, so I started a new project, let’s called it NewApp. I have made the NewApp folder into a git repository by calling git init.
I have then staged the changes and committed them.
I then added the repository
git remote add github github@github.com:myAccount/myRepo
I now want to push to the repository under branch named development. So I use git push github development
After which I get the error error: failed to push some refs to git@github.com:myAccount/myRepo.git
All the explanations that I can find on the Internet suggest you first have to do a git pull from this branch. I don’t want to do that because it will give me the old code which is totally different. But I did it anyway, and then changed the code, but it still didn’t work for me.
What is going on. Why can’t you just overwrite what’s currently in a particular branch?
By creating a new repo (
git init), you are effectively making a new root commit, that you won’t be able to push to an existing repo.A
git pullwouldn’t solve anything, since there would still be two root commits.For your reorganization, I would rather recommend making a branch from an existing commit (meaning, cloning your existing repo and making a branch in that cloned repo), instead of initializing a brand new repo.