0

I am not very experienced with git and I used it only for very basic things, mainly copying commands from webpages and run them without really understanding what is going on under the hood.

So recently, I moved my bitbucket repo to a new pivate github repo. My goal was/is to only use github in the future. I did this with laptop A.

But yesterday I made a mistake: I committed some local changes I had on laptop B to git and pushed it to the old bitbucket repo.

So now I have a small problem: I want to add these changes to my new github repo, but I don't know how to do it and I don't want to mess things up.

Could someone give me a step-by-step instruction how to do that, and on which laptop? I can only guess I wil have to download the bitbucket repo and push the latest commit to github, but I don't know exactly how.

flo
  • 559
  • 1
  • 8
  • 26

1 Answers1

1

Git is a decentralised version control system, so it is designed to work with multiple remote repositories. You can add your github/bitbucket repository as a new remote of your local repository with the following command :

git remote add <remote-name> https://github.com/user/repo.git

Then, if you want to push to a specific remote repository, you can use this command :

git push <remote-name> <remote-branch>

You can find a good introduction of working with multiple repositories in the Pro Git book.

spidyx
  • 1,067
  • 9
  • 16
  • Thank you. I had some issues with your instructions. First, after the push, I got an error saying "Updates were rejected because the remote contains work that you do not have locally.". To check, I ran a fetch and tried again. Didn't work again because "tip of your branch is behind itrs remote counterpart" and it asked me to merge. But git diff showed nothing. So I did a git push -f which finally worked. A bumpy ride. – flo Feb 21 '19 at 20:21
  • I can't tell what git showed you or what you should have done, but be carefull with `git push-f`. It erase your remote branch, no matter what, so you may loose works. You can look at the `--force-with-lease` option, it is more secured. – spidyx Feb 22 '19 at 08:37
  • What do you mean, it erases my remote? Fortunately it didn't do that :) It worked satisfyingly. – flo Feb 22 '19 at 09:56
  • 1
    I mean it replace the content of remote branch you are pushing into by your local content. If multiple users push to the same branch, and you have a local commit not based on the top of the branch, pushing using the `-f` option will replace other's commits. Using `--force-with-lease` can avoid that. See https://stackoverflow.com/a/33247427 for an illustrated explanation – spidyx Feb 22 '19 at 10:02
  • Ah I understand, that makes sense in this scenario. I am working alone so it had no impact, but I will remember it and check your example. Many thanks again. – flo Feb 23 '19 at 15:00