Reputation: 51100
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 [email protected]: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 [email protected]: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?
Upvotes: 1
Views: 954
Reputation: 467081
I think the error failed to push some refs
arises because:
git push github development
... is equivalent to:
git push github development:development
... in other words, push the local branch development
to the remote branch development
. Since the remote branch will be created on a push if it doesn't already exist, I guess that your local branch is called master
and there's no local branch called development
. Assuming that you want your branch to be called development
locally as well, you could do:
git checkout -b development
git push -u github development
(You only need the -u
once to set up an association between your local development
branch and the one on GitHub.)
Update: What I've suggested above should work, but as VonC points out in his answer the right thing to do would have been to clone the existing repository, create a new branch based on master, and then commit your new version on that branch. That way you have some common history, and this will (a) make merging much easier for git and (b) represent the history of your project more accurately.
Upvotes: 2
Reputation: 1323653
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 pull
wouldn'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.
Upvotes: 4