Copy files from one remote to another using GIT

Asked

Viewed 1,430 times

5

I have two configured remotes, origin (Heroku repository) and github (github repository). In my local repository I made several changes but I gave the "push" only in origin, leaving github without updates and commits. Now I would like to know how do I "copy" the origin (Heroku) straight to github.

The steps I took were as follows:

git clone [email protected]:meurepo.git meurepo
cd meurepo
heroku create
git remote add github [email protected]:meuusuario/meurepo.git
git push github

At first he said that there was no data to update and that the repository was already updated but I knew it was not. After some commands like git remote update I tried to give again git push github and now appears the following error:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:rodrigokiller/speedup.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I tried to give the git pull but the same error appears (from [Rejected]).

  • How was your pull? You need to set the remote and branch in the command git pull github master

  • my pull was git pull github master.

  • If I give a git push --force github master there is some problem?

2 answers

1

Just set the new remote and give a push for the same.

git remote add <nome do novo remote> <url do novo remote>
git push <nome do novo remote> <url do novo remote>
  • Ah, you see, that’s what I did, as in the initial post.

  • Try to give a git checkout to the new branch, a git pull -u <nome do branch> and then a push.

1

I was afraid about trying to fix the git pull github master because as I understand it, the "low" pull to the local repository, and since the github remote was outdated, I preferred to opt for the command that I was also afraid of:

git push --force github master.

By using this command, it worked and it seems that the new changes are now going to the two remotes (of course, by pushing each one separately).

  • 2

    What seems to have happened is that your local branch diverged from the remote branch on Github. The push --force "overwrite" the remote branch with the local branch. If this is the desired effect of forcing the remote branch to look like the local one, this is the correct solution, but note that this branch divergence may be due to another contributor posting commits on the remote branch that were not pulled into their local repository. In this case, you need to merge (or rebase) new commits and then publish your local branch.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.