0

I've seen a few similar problems here on StackOverflow but I haven't found 1 that fits what I need.

Here are some I've looked at that don't seem to solve my problem:

How to move files from one git repo to another (not a clone), preserving history Moving Git repository content to another repository preserving history

I have a repository on Bitbucket that I have added to Github. However the one on Github retains it's own history. How can I import the history from the original Bitbucket repository into the Github repository without touching the files? Both repositories already exist.

Community
  • 1
  • 1
theintellects
  • 1,320
  • 2
  • 16
  • 28
  • ...clone from Bitbucket, then push to GitHub? – Ajedi32 Jun 23 '14 at 19:20
  • @Ajedi32 It only seems to copy the files...all the branches and commit history from the bitbucket repo doesn't move over. – theintellects Jun 23 '14 at 19:21
  • Not sure what you mean. Files *can't* exist in a git repository without being on a branch. So if the files are there, there *has* to be at least one branch (`master`?) on GitHub. – Ajedi32 Jun 23 '14 at 19:23
  • @Ajedi32 Sorry, I meant `master` branch does copy over but not any of the branches or commit history (I'm not too concerned with the branches as I am history). – theintellects Jun 23 '14 at 19:25
  • Could you clarify what you mean by "commit history". Again, there has to be at least one commit. Otherwise `master` couldn't exist (there'd be nothing for it to point to). Are you saying everything got squashed down to just one commit? – Ajedi32 Jun 23 '14 at 19:27
  • 1
    "*I've seen a few similar problems here on Stack Overflow but I haven't found 1 that fits what I need.*" **Please link to what you have looked at but didn't fit**, so that other people are better able to help you. Your question is possibly a duplicate of other questions on Stack Overflow. –  Jun 23 '14 at 19:30
  • @Ajedi32 Okay for example: The Bitbucket repo has over 4000 commits from various team members. The Github repo that was simply a clone + added gitignore + push only shows commits for adding the files to the repo + adding gitignore. – theintellects Jun 23 '14 at 19:50
  • @Cupcake Added some links that don't seem to solve my issue, thank you. – theintellects Jun 23 '14 at 19:50
  • If that's the case, I'm guessing what you did was actually not a clone. Instead, you copied *all* the files manually from the old repo, added them *all* to the staging area, added the gitignore, committed, and then pushed. Is that correct? – Ajedi32 Jun 23 '14 at 19:52
  • @Ajedi32 That may be correct, it's been a while. I'm currently trying your answer below, will update if it works. – theintellects Jun 23 '14 at 19:54

2 Answers2

1

I'd probably do it like this:

git clone --mirror <bitbucket repo>
cd <repo>
git push --mirror <github repo>

That basically copies everything from Bitbucket to GitHub, including branches, tags, and other refs.

theintellects
  • 1,320
  • 2
  • 16
  • 28
Ajedi32
  • 45,670
  • 22
  • 127
  • 172
0

If you have the branches in your local repository, and have set it up to point to GitHub, you should be able to just do git push origin [branch name] for each branch. Or something like git branch | xargs -L1 git push origin to do them all at once.

Jeremiah Orr
  • 2,620
  • 1
  • 18
  • 24