Avoid Paying Bitbucket for Git Storage

I’ve been using Bitbucket for my personal development projects for quite some years now without too many issues. They triggered my interest in the times that GitHub was payable and Bitbucket was providing a free git hosting service, great so far.

Recently one of my git pushed failed because apparently I crossed over the 1 GB hosting limit, a new limit which they decided to apply recently. After some investigations I saw that their website was showing this: Your workspace has exceeded the 1 GB limit and has been placed in read-only mode. Learn more about upgrading your plan and checking storage usage. — Learn more

I actually have around 14 GB of repositories already, and understand that things cost money.

Their new hosting tiers are not very large on storage neither: 5 GB standard edition and 10 GB for the premium edition. So… I went on exploring to self hosting the git repos on my own server, that I already use for backend services of all my (mobile) applications. I host this on Linode with very good experience.

It turned out that this went very smoothly and should have done sooner probably.

Here is what I did — my sever is running Ubuntu Linux by the way.

// update the server packages
sudo apt update

// install git
sudo apt install git

// add the git user
sudo adduser --system --shell /usr/bin/git-shell --group --disabled-password --home /home/git git

// create a home directory
sudo mkdir -p /home/git/repos

// change the ownership
sudo chown -R git:git /home/git/repos

// go to the new repos dir
cd /home/git/repos

// initialize a bare repo that you are hosting already on bitbucket
git init --bare todoapp.git

// change the ownership again for the new repo, do this every time you initialize a new bare repo
sudo chown -R git:git /home/git/repos

// now open a terminal session on you local pc and go to the directory of the application already under git control

// example 
cd /username/todoapp/

// set the new remote repo location, replace the IP with the address or IP of your server.
git remote set-url origin git@139.122.121.21:/home/git/repos/todoapp.git

// if you get an error here check in /username/todoapp/.git/config what is here: [remote "origin"] sometimes origin is called something else.

// now push any new code changes and it will upload the whole local git repo to the new server. I use SourceTree to push all branches.

After I’ve done this for all my applications, I went to the server to check the size of the pushed repos, I found that Ubuntu’s free tool ncdu is great for this.

Screenshot

Thanks to Bitbucket for all the years of free hosting ♥️ — and I keep my read-only 14 GB repose there for free as a second cloud backup, you never know.