15 апр. 2016 г.

How to handle big repositories with git

Shallow clone

Clone a repository keeping only the latest n commits of history. You can properly pull and push to repositories even from a shallow clone.

git clone --depth 1 remote-url


Clone only one branch

You can also limit the amount of history you clone by cloning a single branch

git clone URL --branch branch_name --single-branch [folder]


Sparse checkout

Original StackOverflow answer

mkdir <repo>
cd <repo>
git init
git remote add -f origin <url>
git config core.sparsecheckout true
echo "some/dir/" >> .git/info/sparse-checkout
echo "another/sub/tree" >> .git/info/sparse-checkout
git pull origin master

Another way:

git clone
git config core.sparsecheckout true
echo src/ > .git/info/sparse-checkout
git read-tree -m -u HEAD


Sparse checkout + shallow clone

Original StackOverflow answer

git init <repo>
cd <repo>
git remote add origin <url>
git config core.sparsecheckout true
echo "src/*" >> .git/info/sparse-checkout
git pull --depth=1 origin master


Disable delta compression for binary files

Original discussion

Configure a .gitattributes file as such:

*.jpg  binary -delta
*.png  binary -delta
*.psd  binary -delta

... and so on


4 апр. 2016 г.

Premature optimization


Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

Knuth, "Structured Programming with Goto Statements". Computing Surveys 6:4 (December 1974), pp. 261–301, §1.