From github to bitbucket - github

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.

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.

How to send a GitHub Pull Request to multiple repos

I have a project on GitHub, and I forked it to a second repository.
There is still work done on the repo that I forked from, but the changes I make to the first repo should also be applied to the forked one.
How can I push a pull request to both of them at the same time? Or is that impossible to do in a simple way?
If it is, is there a simple alternative solution?
No, GitHub pull requests only target a single repository.
Pull requests are only relevant when you are communicating with other people. Since both repositories are yours, you can just execute a git pull or git merge command on your local machine to merge whatever branches you want to merge. Then use git push to push the changes up to GitHub if you want.
Also, I recommend that you simplify this setup and just use a single GitHub repository with multiple branches.

Import contribution to github from bitbucket

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.

Mercurial: Merge two local repos

I'm using Mercurial with TortoiseHg on a Windwos host.
We have a central repository for the team and it must always be in a stable state.
Now I'm working on a feature with a colleague and we want to merge our work, without going via the central repository because our work isn't stable yet.
So we have a common ancestor, then we have individual commits to our local repos and we need to merge this work and test it, before pushing it to the central repo.
How do we do that?
As a an additonal difficulty, I'm working on Windows with TortoiseHg, while my colleague is on a Linux box. We're both only basic users of Hg, so apologies if this is a question with an evident solution. For me it isn't.
You can use named branches and create special named branch (pushed to central repo) for your WIP
You can use Mercurial in true DVCS-way:
Start embedded web-server on both sides hg serve in the Working Directory
Get URL of repo
Pull from remote side hg pull URL-OF-REMOTE-REPO

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.