All Articles


‘Github is the social media for developers’, this is the first thing that came to mind in an interview. I was pre-beginner in version control then. GIT is the functionality for distributed version control and source code management that is offered by Github, Bitbucket, GitLab to mention a few. Just so you know GIT is used for other things other than source code.

As much as you can have the above done locally, Github (originally known as Logical Awesome LLC) is the most popular hosted service and it offers a lot of features. Most of these offer plans for both private repositories and free accounts. For comprehensive GIT documentation check this:

Let’s talk about pruning GIT. In one’s account, you get to have as many repositories as you like. (A repository is a collection of files and folders that are tracked using git. I’ll assume that you know enough about GIT moving forward)

  • Removing stale Git branches

Every developer and team have their own git branching workflow or models. Talk of:

  • Develop-Master
  • Develop-Staging-Master
  • FeatureBranch-Master
  • one branch model Master, the list is endless.

Whenever a feature branch is merged to the main branch, I advocate that you delete the branch or set a time period for doing that, say 2 weeks. Github has a button for this on the PR page. I’m not sure if this can be automated. This helps maintain a short list of manageable git branches

I earlier thought that having many branches affected the size of the repository. This is not true!

My friend recently told me this when they hit the Bitbucket maximum capacity: 2GB. (Yeah, I was also baffled) The repo isn’t even close to being huge when cloning. Seeing that the repo had 170 branches I was prompted to write this article to help others like him who may not be aware of this.

Turns out our deduction that multiple git branches contributing to the size of the remote repo is not true at all. Git works with hashes and diffs. It’s a bit complex but this article goes into the nitty gritty. We suspected that it is either a Bitbucket issue or a GLFS issue.

It is considered not good practice to have so many branches that are not active. Here is a script for deleting branches that are inactive.

git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads | grep -v "master" | grep -v "develop" | grep months | awk '{print $4} | xargs git push origin -d

To delete branches we run:

Local branches

git branch -d {the_local_branch}  // --delete
git branch -D {the_local_branch}  // --delete --force

Remote branches

git push origin -d {the_remote_branch}  // --delete

and run this as frequently as possible especially after deleting branches remotely bash git remote prune origin

  • Git modules

Good code is modular and git modules helps in this. To understand git modules think of it this way: One directory in a repo being an entire separate repository.

Take this, for example: In this repo we have aresivel @ c4e5884 which links to a separate repo.