Git: A Happy Repository is a Lightweight Repository
Join the DZone community and get the full member experience.Join For Free
i have had the joy of working with some great teams and learning how they use git, but i have also seen it misused and the number one issue i helped teams resolve when using git is what i call, the fat repository . the fat repository (not to be confused with the funny & nsfw fat git enterprises ), is an especially easy trap to fall in for teams who have come from the client/server source control world (svn, tfs, cvs etc…) because in their world, a fat repository isn’t a harmful thing and even may be a good thing – but in the dvcs world the fat repository is a major problem.
a fat repository can be one of the following two characteristics, or it can have both of them. i think both of these characteristics will be familiar to most developers who have used some sort of source control any period of time.
characteristic one: multi-tasked repository
the multi-tasked repository is where you have a single repository which has multiple root folders and each folder is for a different customer or project. this is very common with internal focused items. for example a consulting company may develop a set of common libraries that are used in a variety of projects and put all the common libraries code in a single repository, so they are easily accessible for everyone in the company. another example would be a department in a company, which has all the projects that single department has developed in a single repository.
many people, myself included have multiple visual studio projects inside a single repository, that is no problem – where it becomes a fat repository is where those items/folders/projects are not related to each other from a delivery perspective. often those projects only are lumped together, because they share some common organisation relationship.
the reason this is called multi-tasked repository, is because the single repository is responsible for multiple unrelated deliverables.
characteristic two: multi-focused repository
the repository where it has not fallen into the multi-tasked trap can still become fat. this often happens when a single repository is used to handle many requirements beyond code of a single deliverable. a common example of this characteristic is when you have a documents folder or database backup folder in your code repository. here the core issue is that while everything is related to the software development, not everything relates to the building of the code.
this is named a multi-focused repository because the focus is split between specs, database backups, virtual machines and the code (for example). i find this issue hits not only repositories, but tools like dropbox where you get a folder shared because you need one document and you end up syncing 100’s of other documents, backups, install files and what-nots that you don’t care about too!
fat repository – summary
in short a fat repository is one where there is more going on in a repository than just code & just the code that is needed for a single project or deliverable.
there is a simple test to identify a fat repository just ask: is everything in here vital my deliverables? if there are items that are not vital – you have a fat repository.
client/server and the fat repository
in the client/server world of source control, like svn or tfs, this isn’t actually an issue and it is very common to find fat repositories. in fact i would say if you are using a client/server source control – having a fat repository is an advantage since there is a single place to go to get everything you need.
the reason this isn’t an issue in the client/server world, like we will find out in the dvcs world, is because of two key differences:
- in client/server you have only a working set, not the entire repo. so you initially need to pull a smaller set down to your machine, compared to pulling down the working set & all the history in dvcs.
- in client/server because you are working with a server, you can checkout a single sub-folder or even a single file without needing the rest of the files in the repository.
dvcs and the fat repository
the dvcs world of mercurial & git works completely differently to the client/server world. firstly the repository is comparatively cheap to create – just type git init and viola, a repo. in client/server you need a server admin to create one, this relative cheapness encourages you to create loads of repositories – some may last & get a remote version on a server and some may live short lives just on your machine – that is perfectly fine.
secondly, when you grab a repository for a team you not only get the one folder you want in a working set version – you get everything. every folder, every file & all the history for it.
this is where it becomes painful to deal with a multi-tasked repository or a mutli-focused repository because you are forced to pull down content that you do not care about.
issues a fat repository causes
initial check out times that are ridiculously long. most of the time this is a once off pain but it is still a pain. i say most of the time, because i went to help a team that had each deliverable in a separate multi-focused repository and while the working sets were small and the team members had no issue with the one long initial check outs – the senior developers that floated between the teams to help out found that pulling the repositories down was ruining their productivity, especially if they were just trying to help with a single bug. this teams repositories were so huge that most people couldn’t keep more than two around, even though the working sets were less than a gig.
disk space usage. you developers want a ssd and while it will make them more productive it also means that space is a premium or you will be forking out a lot for those massive ssds. with dvcs, they get everything in the repository including all the history. check in a 1gb database backup, then delete it… in the client/server world the working set wouldn’t be impacted, but in the dvcs world everyone will pull that 1gb file down initially and that means a lot more disk space usage.
solution: the lightweight repository
so when using a dvcs, the solution is simple:
- keep the repository as lightweight as possible – only check in the things you need. this means taking care about what is checked in & using functionality like .gitignore & using staging to ensure you only check in what you should.
- since dvcs repositories are cheap, have loads of them – have one for documentation, have one for code, have one for artwork etc… that way those who need something can cherry pick the repositories they need.
- avoid the law of the instrument – just because you can put things in repo’s doesn’t mean you should. do you need the history on every db backup, not likely – a file share or dropbox maybe enough for those! or why not use a tool that is better suited to word documents, with the ability to index their contents so that they can be searched, for example sharepoint. tfs does this with the full version – where every repository gets an sharepoint site to put the documents in.
in short a happy repository is a lightweight repository!
Published at DZone with permission of Robert Maclean, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
TDD vs. BDD: Choosing The Suitable Framework
Adding Mermaid Diagrams to Markdown Documents
Azure Virtual Machines
A Complete Guide to Agile Software Development