Copy a Bitbucket Repository from one account to another bitbucket account
Asked Answered
E

4

27

my friend have a repository on Bitbucket and I want to copy that repository (for future reference so that if he delete that repository i would still have one copy) to my bitbucket account. I tried bare-cloning,mirror push and etc... but :(

may be I'm missing some set of commands

PS: repository type is git (not hg)

Epiphany answered 3/12, 2013 at 5:32 Comment(2)
Something like https://mcmap.net/q/89509/-how-to-migrate-git-repository-from-one-server-to-a-new-one ?Takishatakken
Something like git remote add github https://github.com/myhappyproject will give the repo at https://github.com/myhappyproject the name github, so that in the next command you can do git push -f --tags github refs/heads/*:refs/heads/* to push to that url.Takishatakken
A
66

Recently, I had to do this for multiple repositories. I found a better way than cloning the repo locally and pushing it to another remote(on Bitbucket).

Bitbucket provides import repository feature. It can be found under Repositories > Import Repository

Bitbucket - Import Repo

Just provide https url of the repo and access credentials, and bitbucket will do the rest for you.

I know this is an old question but this method is easier and saves a lot of time. Hope this helps others in future.

Acrylyl answered 7/5, 2015 at 7:13 Comment(4)
Does this import the Team also? (This may be a stupid question - I am new to Bitbucket)Cirrostratus
Sorry, I didn't understand your question. If your working in a team, this won't import other repos of the team. If that's what you wanted to know.Acrylyl
Does it always have to create a new repository? I've been given an admin access to the one new, but empty repository, then I need to import different repository. It seems that it would create a new repo instead.Patricepatrich
Yes. You use the method described in poke's answer.Acrylyl
P
14

If you have access to that repository, then simply cloning it to your local machine is all you need to do to get a full copy of it. For example:

git clone [email protected]:username/repository.git

Now, if you want to store a copy of it online, you can just create a new repository on Bitbucket where you push to. After filling out the form there, Bitbucket will give you a quick help on how to push your data inside. Choose “I have an existing project” and the following will show up:

Already have a Git repository on your computer? Let's push it up to Bitbucket.

cd /path/to/my/repo
git remote add origin [email protected]:your_username/new-repo.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags

Want to grab a repo from another site? Try our importer!

You just need to follow those instructions closely. You will have to choose a different remote name though as with your cloning, origin is already taken:

git remote add mycopy [email protected]:your_username/new-repo.git
git push -u mycopy --all
git push -u mycopy --tags

Or you have to remove the origin remote first:

git remote remove origin

After pushing, your repository at Bitbucket will have the full contents, so your backup is ready.

The other, and probably simpler, option is to simply fork your friends’ repository directly. You can do that by visiting the Bitbucket page, then click the “…” icon in the top left and choose “Fork”. This will let you create a direct copy of the repository directly on Bitbucket.

Paluas answered 15/4, 2015 at 15:49 Comment(2)
Wait... why this answer to such an old post??? Let's see... stackoverflow.com/users/216074/poke?tab=topactivity. Riiight: "next badge: "version-control". Sure. +1 then (because this is a good answer, of course).Neb
@Neb Haha, you got me! To be fair, I didn’t realize the question was this old until I already clicked on the save button. I blame the unanswered questions list for being terribly sorted ;DPaluas
D
5

I would like to note that BitBucket has redesigned their site and the Import Repository feature is now in the Create Repository (the '+' icon) menu as an option.

You simply paste in the repository URL and check the box for Requires Authorization and it should auto-fill your current login credentials and auto-populate the slug name. Change the slug to whatever you want and click import.

You get an email when the import finishes and there is a progress bar on the page if you want to sit and wait.

I'd also like to note that I can post an answer but can't comment on Parkar's answer because I don't have 50 reputation.

EDIT: Just in case you're new enough that you can't find the repository URL, you can get the URL from going to the repository, hitting the Clone button and copying just the URL portion of the clone command it pops up with. You may also need to change the selection drop down from SSH to HTTPS for the authorization to work automatically.

Dowd answered 19/10, 2018 at 16:32 Comment(2)
this is the most relevant answer todayLymanlymann
the import feature seems broken always throws an error, the method in poke's answer always works.Sacerdotal
F
0

For me i had to bring the history also to the new repo. So, I found the --mirror command of git very helpful for this one.

You just require to do a git pull of current master in local , be on desired branch then: git push --mirror destination-repository-url

And thats all you require, it will transfer all the tags, branches , commit history to the new repo.

Provided you've the write access on the target repo for the selected branch.

Filippa answered 14/6 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.