Reputation: 1132
I have been using GitHub for my remote repo and need to switch to bitbucket. Currently, my local repo is synced with GitHub. I tried the following: To delete the association with the GitHub remote:
git remote remove origin
The bitbucket repo came with a .gitignore
and README.md
file. I deleted both of these files on the bitbucket master repo.
To add the association with the Bitbucket remote:
git remote add origin https://[email protected]/dir/my_project.git
git push -u origin master
which resulted in:
To https:///[email protected]/dir/my_project.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https:///[email protected]/dir/my_project.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
So I thought I needed to do a git pull for some reason--eventhough I deleted everything on the bitbucket repo.
This resulted in:
git pull
warning: no common commits
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 8 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.
From https:///[email protected]/dir/my_project
* [new branch] master -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Then I tried:
git pull origin master
From https:///[email protected]/dir/my_project
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
I don't really know what I'm doing here. Should I use the following?:
git branch --set-upstream-to=origin/master master
If so, why?
Upvotes: 0
Views: 77
Reputation: 43718
The Bitbucket repository would be an entirely new repository, unrelated to your local repository. If there's nothing of value in your Bitbucket repository you can force push to the origin.
git push --force --set-upstream origin master:master
This will overwrite the origin's master
with your local master
and setup the remote-tracking branch. I've used the long version of the flags to be more explicit, but -fu
would have done the same.
Upvotes: 3