Import contribution to github from bitbucket - github

I just got a new job recently, and all repos of their projects are on BitBucket.
I used to use a lot GitHub, so I was wondering if there is a way to sync contribution between the two.
I have already tried https://github.com/jrm2k6/contwidgetor. It seems like a way to do it but didn't work for me somehow, and there is only limited support of it.

You can use Contributions Importer for GitHub
It copies all commits from source git repositories to a mock git repository. Each copied commit will report the same commit date, but the original code is not copied, neither the commit message.
The mock code is generated using the same language of the original source repository.
For example, I have a mock repository on my profile that reports all the activities of all my private repositories.

You can at least manually mirror any Git BitBucket repo from BitBucket to GitHub:
git clone --mirror http://user#bitbucket/user/repo.git
git remote add github http://user#github.com/user/repo.git
git push --mirror github
(Create an empty repo on GitHub side first)
Then, on demand, you can go into your local clone, do a fetch, and then a git push --mirror github again to sync new commits.

I was in the same situations, so I just whipped a node script together. I think it's more simple (implementation wise) than the solution posted by mir88.
The program then makes a shadow repository on GitHub. Each Bitbucket repository is represented by a file, and each Bitbucket commit is reflected by the Bitbucket commit hash.
The Bitbucket hashes are added backwards in time so the match the point in time when the original commit was made on Bitbucket.
Should be easy to change to your exact needs.
Feel free to check it out: Bitbucket 2 GitHub Activity Sync.

Related

After a github fork, how can I compare my branch to a branch in the upstream repo?

I was trying to compare changes I made to a forked repo.
To make this real, here is the example:
I forked https://github.com/springframeworkguru/sfg-di as https://github.com/steranka/udemy-sfg-di.
I got a local copy of the (forked) repo git clone git#github.com:steranka/udemy-sfg-di.git
I changed to the branch I wanted to work on git checkout property-source.
Made changes and committed the changes (to my local repo).
Push my changes to my fork so the changes can be compared to the original repo. git push
Now I want to compare my changes to the equivalent branch on the original repo.
The origin and upstream are set to:
origin: git#github.com:steranka/udemy-sfg-di.git
upstream: git#github.com:springframeworkguru/sfg-di.git
Searching for solution
My searches indicated that there was not a built in way to do this using the git CLI, nor the github website.
What I did find was:
https://stackoverflow.com/a/66613981/3281336. Basically do the compares via local repo.
How to compare a local Git branch with its remote branch - How to compare local vs remote branch. Later, I learned this is basically what a forked repo is... Just another remote.
General info about forks (from GitHub.com) https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests - The GitHub.com docs indicate that this is doable if you create a pull request. This is not what I want to do.
My question
How do you do this? I ran across gh-cli which might do it.
Can this be done via the github.com web interface? If so, how?
Append /compare to the URL of your repo. Example (try it):
https://github.com/mattneub/amperfy/compare
That's a public fork of a public upstream. You can select two branches, possibly at the two different repos, to see the diff.
I've selected the answer from Matt because that is the answer I was looking for. But another possible solution is based on #torek's answer.
The solution is to pull the upstream repo's branch that you want to compare locally and then do normal git diff commands. The result is that the compares are done via my local repo.
The steps to do this are:
Setup the pointers to the upstream (the repo you forked)
Get the upstream source and put it into your local repo
Compare the upstream source's (local copy) to your code.
The code commands to do this are:
git remote add upstream git#github.com:springframeworkguru/sfg-di.git
git fetch upstream property-source
git diff upstream/property-source..
This turned out to be simpler than I expected.
One benefit of this approach over the GITHUB web ui is I could compare my code changes without pushing my code to the github.

Bitbucket to github migration of an already existing repo

we have migrated from bitbucket to github 4 months ago but our team members are still using bitbucket. So, now we have decided to completely moved to Github and use its sevices. So, i want to know whether we can still use mirroring or not to migrate all the changes in bitbucket to github or we have to push it manually or using git push --all.
It depends if there was concurrent activity both on GitHub (the new repository) and BitBucket (the old one)
If that is the case, I would prefer asking each developer, in their own local repository, to:
add the new repository as a remote 'gh'
fetch from it
rebase their branch on top of gh/their-branch (for branches that were modified both on GitHub and BitBucket)
push new branches (done only on BitBucket)
That way, each developer can resolve any conflict locally first, before updating the new GitHub repository.

Git completely replaced changes in history. How to restore files?

I have git repository on bitbucket. I use it from Eclipse for a while, but then copy Eclipse project with local git repository to another place on the filesystem and work locally for 3 weeks. I'm a newbie with git, so I just copy the project as is.
Yesterday I try to push local changes and then switch to the remote branch. Now I see in git-gui only old bitbucket commits and no new files. I search in git-gui everywhere. But the size of the repository tells me that my new files are still there (on bitbucket 16mb, locally >300mb).
git branch shows me 2 branches (master and * (no branch)) and both have bitbucket commits. I didn't make any branches, I just first cloned the repo from bitbucket, then made commits, then made some actions trying to push the copied repo and then change branch. Any idea of how can I restore my local files will be greatly appreciated!
I'm really having a hard time understanding what the exact situation is.
However, if you say all the files are still in the local repo, a simple:
git reflog
is all you need to see recent commits on all branches. Find the right commit you want to go back to, and take it from there.

How do I get MercurialEclipse and Bitbucket to talk to each other?

I'm an Eclipse user, but I'm a newbie to Mercurial and to Bitbucket. I think I understand the command-line hg commands. I can create repositories, clone, push, pull, update, that stuff.
If I have a project in Eclipse, I can create a local repository for it. I can't figure out how to clone this repository up to Bitbucket.
If I have a project in Eclipse, I can create a remote repository on Bitbucket. Then I don't have a local repository, so I can't use any of the Team... commands, and can't do anything.
If I have a repository on Bitbucket, I can't get to it, because I don't have a local repository, so again I can't do anything.
If I create separate repositories locally and on Bitbucket, then I have two different repositories, and I don't know enough Mercurial to merge(?) different repositories.
There must be some blindingly obvious to get a project off the ground, but I'm blind to it. I can do this just fine from the command line, but MercurialEclipse is defeating me. No luck so far with Google and assorted documentation...
Help?
Doing it using Eclise "Team" UI:
Create a project in Eclipse and "share" it using Mercurial repository type. That will create local repository (by default in the same location where your project is).
Create project repository on BitBucket.
Use "Team">"Push" to push local changes to your remote BitBucket repo. First time it will ask you to enter the repository URL, user name and password. All this information is available on your Bitbucket web UI.
Don't forget that you have to do 2 stage commits after that. Commit in Eclipse UI will commit it in your local repository. In your team perspective's Synchronize view you will see additional "Outgoing" and "Incoming" entries. Using right-click menu on them you will be able to push/pull your changes to/from your BitBucket repo.
Remote repo information can be managed in special "Mercurial Repositories" view.
More info can be found in the tutorials at http://ekkescorner.wordpress.com/blog-series/git-mercurial/
Following the directions provided by bitbucket should be enough.
You can either create a repository on bitbucket and clone it on your desktop:
hg clone https://bitbucket.org/youraccount/yourproject
...
hg pull -u # to pull changes and update
hg push # to push changes to this repo
Or use a local repository and push these changes to a newly created repository on bitbucket:
cd /path/to/existing/hg/repo/
hg add [...]
hg commit
hg push https://bitbucket.org/youraccount/yourproject
Basically, two repositories are "bound" by:
a common changeset in their history
the [paths] configuration in /path/to/existing/hg/repo/.hg/hgrc, that lists remote repositories you can read/push to.

From github to bitbucket

Imagine situation like this:
You have a working repo in bitbucket - you were pulling revisions from another bitbucket repo in Windows 7 through TortioseHG.
Now the second project has moved to Github system and you can not pull from it anymore.
So my question is like this:
How can i somehow create new repo in bitbucket where I will pulling changes from github and from this repo i can easily pull in Tortiose HG to my working repo?
I do not want to use Github etc, so please do not advice it to me etc just help me with my question. Thank you.
The ideal solution consiste to keep local Mercurial repo, and work only with this local repo to the existing bitbucket Mercurial remote repo.
With a plugin like Hg-Git, you can at least push to and pull from a Git server repository from Mercurial, allowing you to pull from the GitHub repo to your local Mercurial repo.
From that local (Mercurial) repo, you can then work as usual with the bitbucket remote repo.
The OP adds:
It didn't work for me so i tried to transfer git repo to hg repo and from this repo pull to my working repo with changes - but it says that: abort: repository is unrelated - but I merged a lot from it. Any help here?
That makes senses, if both repos have been developed separately, you cannot push/pull 2 (mercurial) repos one into another.
This is confirmed at the bottom of the page "Understanding Mercurial", and detailed in the blog post: "What Mercurial Can't Do: Subtree Repos".
The more practical solution would be to make one extra repository (a "parent one") with your two repos declared in it as nested repository.
It would keep both repos independent, allowing to push back to the GitHub repo from your second mercurial repo.
If you don't have to push back to GitHub, but really want to have one repo in which you merge common files, then you can look in "Merge tip from an unrelated repository with Mercurial", but that is much more complex.
I would rather:
keep both repos separate
delete from the first one the common files you need to merge in the second one.
report and merge those common files in the second one.