Moving Bitbucket Git Project to Github and more
I was using github.com for some of my open source projects since 2011. But most of my private project was hosted in bitbucket. Recently I subscribed github.com‘s private hosting and moved some of my projects from bitbucket. Here I will discuss some problems I faced and how I tackled those problems.
1. Easy way to move bitbucket project to github with history
In the github.com site at the menu bar you will see this option. Click the + sign and then click IMPORT REPOSITORY
After clicking that you will see the following options. You have to provide the bitbucket URL, you can mention private/public and also you’ve to give the new repository name in github for the project.
Then click BEGIN IMPORT. If there is no issue you’ll get a confirmation mail about new repository. If it failed you will also receive a mail without detail description.
2. Tackle file size issues in Github
Github shows warning if a file size is over 50 MB and it doesn’t allow file size over 100MB. In my case the first way doesn’t import some of my projects from bitbucket. So how I tackled it. There is 2 ways
- I can forget about history and make a new project locally and copy existing code without .git history and push them to new repository in github.
- I can follow the solution BFG Repo-Cleaner
In my case and for one project I followed the BFG Repo-Cleaner solution
3. Changing remote branch from local repository
If you do not want to follow the first solution, you can also change the remote branch in you local repository and push it to github.com new repository.
To do this, first create a new repository in github.com. Now open your terminal and write the following commands
1. Go to you local repository in terminal
2. Rename remote branch from “origin” to “bb”
git remote rename origin bb
3. Add github web url as remote branch “origin”
git remote add origin https://github.com/mahmudahsan/AppsPortfolio.git
4. Push the repository to github
git push -u origin master
5. Remove the bitbucket remote branch
git remote rm bb
4. Applying .gitignore to untrack some files in existing directory
In my case, for some of my iOS projects I tracked cocoa-pods library as well. But when I was moving my project from bitbucket to github I found its not necessary to track those libraries. So to apply .gitignore files in my existing project this is how I solve
Remove files from working tree and index
git rm -r --cached .
Stages new and modified files
git add .
git commit -m ".gitignore works"
Push master branch to remote branch
git push -u origin master