Dercni
Dercni

Reputation: 1224

Git origin to bitbucket

I have a project I have cloned from a public repo to my PC which I have tweaked and pushed to Heroku.
I now wish to push my tweaked code to BitBucket as a backup.

$ git status
On branch master
Your branch is ahead of 'origin/master' by 13 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

$ git remote
heroku
origin

When I try to add the BitBucket command it errors with:

fatal: remote origin already exists

That is, after:

$ git remote add origin [email protected]:me/myproject.git
$ git push -u origin --all # pushes up the repo and its refs for the first time
$ git push origin --tags # pushes up any tags

Would I correct in thinking I just have to update "origin" to point to BitBucket instead of the original repo?

Upvotes: 3

Views: 10156

Answers (2)

VonC
VonC

Reputation: 1329032

Would I correct in thinking I just have to update "origin" to point to BitBucket instead of the original repo?

As a backup it is clearer to just add a new remote

git remote add bitbucket /url/to/your/bitbucket/repo
git push -u bitbucket --all

If you really wanted to change the remote 'origin' (because 'heroku' is enough), then it would have been:

git remote set-url origin /url/to/your/bitbucket/repo

No need for a git branch command, the push will create the bitbucket remote branch for you.

Upvotes: 5

Luke Exton
Luke Exton

Reputation: 3676

So you don't want to add the remote again with the same name, that will always fail. There is nothing intrinsically special about the origin as a name except that it is the convention.

Your current branch is setup to track the remote origin/master. If you want to be able to push directly to your bitbucket as a new repo.

You can add a few remote named bitbucket pretty easy.

 git remote add bucket <repo-url>

And then you can update your current branch to be able to track the bucket master branch

git branch -u bucket/master

So when you run:

git push

it will push your changes directly to bitbucket.

Upvotes: 1

Related Questions