Skip to content

Instantly share code, notes, and snippets.

@gordjw
Created May 5, 2015 10:31
Show Gist options
  • Save gordjw/b8616b7834addc91a6b1 to your computer and use it in GitHub Desktop.
Save gordjw/b8616b7834addc91a6b1 to your computer and use it in GitHub Desktop.
Comparison of git and svn checkout and updates
In which I run some pretty rudimentary tests to find the most efficient way to checkout/update WordPress with git, and compare it to SVN.
First, we'll try shallow cloning, because that's the path to the smallest local git repository.
$ git clone --depth 1 https://github.com/WordPress/WordPress.git --branch 4.1
Cloning into 'WordPress'...
remote: Counting objects: 1421, done.
remote: Compressing objects: 100% (1276/1276), done.
remote: Total 1421 (delta 163), reused 982 (delta 118), pack-reused 0
Receiving objects: 100% (1421/1421), 7.96 MiB | 1.35 MiB/s, done.
Resolving deltas: 100% (163/163), done.
Checking connectivity... done.
Note: checking out 'e5e791f331d371ad6262c1893d84f5f2b6c26464'.
$ cd WordPress/
$ du -hs .
31M .
$ git branch -v -a
* (no branch) e5e791f Tag 4.1
That's great. It's smaller than the related SVN tag in the WP repo.
Okay, so we're at 4.1, let's try updating to 4.2
$ git fetch origin 4.2:4.2 --depth 1
remote: Counting objects: 691, done.
remote: Compressing objects: 100% (418/418), done.
remote: Total 691 (delta 525), reused 380 (delta 264), pack-reused 0
Receiving objects: 100% (691/691), 1.11 MiB | 568.00 KiB/s, done.
Resolving deltas: 100% (525/525), completed with 428 local objects.
From https://github.com/WordPress/WordPress
* [new tag] 4.2 -> 4.2
* [new tag] 4.2 -> 4.2
$ git tag
4.1
4.2
$ du -hs .
35M .
Alright, looking good. We have two local tags now, but storage space only went up by 4MB.
However, we're only half done. We've pulled down the new tag, but the code still says 4.1.
Let's change to 4.2
$ git checkout 4.2
warning: refname '4.2' is ambiguous.
Previous HEAD position was e5e791f... Tag 4.1
Switched to branch '4.2'
$ git branch -v -a
* 4.2 87bf150 Tag 4.2.
Awesome. Code has updated to 4.2, let's do some cleanup and get rid of 4.1.
$ git tag -d 4.1
Deleted tag '4.1' (was e5e791f)
$ git tag
4.2
$ du -hs .
35M .
Hmm, still just as big.
Let's try some garbage collection.
$ git gc
Counting objects: 2112, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1406/1406), done.
Writing objects: 100% (2112/2112), done.
Total 2112 (delta 764), reused 2018 (delta 670)
$ du -hs .
33M .
We saved a couple of MB. Let's see how that compares to a shallow clone of 4.2 directly.
icarus:Downloads gordon$ git clone --depth 1 https://github.com/WordPress/WordPress.git --branch 4.2 4.2
Cloning into '4.2'...
remote: Counting objects: 1449, done.
remote: Compressing objects: 100% (1278/1278), done.
remote: Total 1449 (delta 185), reused 819 (delta 144), pack-reused 0
Receiving objects: 100% (1449/1449), 8.05 MiB | 595.00 KiB/s, done.
Resolving deltas: 100% (185/185), done.
Checking connectivity... done.
$ cd 4.2
$ du -hs .
32M .
So, there's clearly something still left over from cleaning up 4.1 in the original clone.
But we saved 3MB by cleaning up the 4.1 tag.
Steps to shallow clone and upgrade:
$ git clone --depth 1 https://github.com/WordPress/WordPress.git --branch 4.1
$ git fetch origin 4.2:4.2 --depth 1
$ git checkout 4.2
$ git tag -d 4.1
$ git gc
I might be doing it wrong, but that's way more complicated than svn switch.
Just for reference, I checked our production environment, which uses SVN, and has been running for nearly 3 years.
$ du -h -d 1 .
6.4M ./wp-admin
12M ./wp-includes
96M ./.svn
7.1G ./wp-content
7.2G .
As you can see the .svn folder is 96MB, the full git clone of WP is 151MB.
Plus, wp-content is over 7GB, so the ~55MB difference is a rounding error anyway!
Alright, let's see how we'd do it with a full repository clone.
$ git clone https://github.com/WordPress/WordPress.git
Cloning into 'WordPress'...
remote: Counting objects: 202214, done.
remote: Total 202214 (delta 0), reused 0 (delta 0), pack-reused 202214
Receiving objects: 100% (202214/202214), 124.01 MiB | 3.42 MiB/s, done.
Resolving deltas: 100% (159359/159359), done.
Checking connectivity... done.
$ cd WordPress/
$ du -hd 1 .
130M ./.git
6.3M ./wp-admin
5.6M ./wp-content
11M ./wp-includes
153M .
$ git checkout 4.1
HEAD is now at e5e791f... Tag 4.1
$ git checkout 4.2
Previous HEAD position was e5e791f... Tag 4.1
HEAD is now at 87bf150... Tag 4.2.
$ du -hd 1 .
130M ./.git
6.3M ./wp-admin
5.6M ./wp-content
11M ./wp-includes
153M .
If I was using Docker, or some other container system, I'd use shallow clones in my Dockerfile, because the containers are supposed to be small, fast and disposable. So we'd never be upgrading "in-container", and we'd only need the shallow clone.
Since we're not using Docker, we may as well clone the whole repository, because switching local tags is instant (unlike svn switch), and getting new tags from remote is only going to require pulling deltas, same as SVN.
There's a time penalty at the initial clone, but we've only done that 4 times in production in 3 years, when we needed to create additional WP Networks.
Afterwards, git seems to be quicker, and the repo size difference ends up being insignificant after sufficient time, because SVN keeps growing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment