Skip to content

Instantly share code, notes, and snippets.

@zoidyzoidzoid
Last active July 5, 2016 06:51
Show Gist options
  • Save zoidyzoidzoid/5703d474a832f9cc5288abe1315e544f to your computer and use it in GitHub Desktop.
Save zoidyzoidzoid/5703d474a832f9cc5288abe1315e544f to your computer and use it in GitHub Desktop.
Notes on Git
#!/bin/bash
#
# Remove all files with a certain extension and add them to git-lfs
#
# Install git-lfs on OSX with `brew install git-lfs`
set -eu
set -o pipefail
EXT=$1
# Remove all the desired files from VCS, but keep them locally
git rm --cached "*.$EXT"
git commit -m "Removed $EXT format from the repository"
# Tell LFS to track this format, has to be done before the files are added
git lfs track "*.$EXT"
# Make sure to add the changes made by LFS above
git add .gitattributes
# Add to LFS!
git add "*.$EXT"
git commit -m "Added $EXT format to LFS"

Notes on Git

Tips for big repos

Use shallow clones (Potentially not single-branch)

git clone --depth 1 repo.git # --single-branch is implied

  --depth <depth>
    Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless --no-single-branch is given to
    fetch the histories near the tips of all branches. This implies --shallow-submodules. If you want to have a shallow superproject clone, but full
    submodules, also pass --no-shallow-submodules.

Note: Don't unshallow a repo, it's better to re-clone

Move static assets/binaries to git-lfs

Run git garbage collection

(GitHub run this on repos once a week or so)

Note: Issues with git gc --aggressive

git gc

Runs a number of housekeeping tasks within the current repository, such as compressing file revisions (to reduce disk space and increase performance) and
removing unreachable objects which may have been created from prior invocations of git add.

Users are encouraged to run this task on a regular basis within each repository to maintain good disk space utilization and good operating performance.

Some git commands may automatically run git gc; see the --auto flag below for details.

Sources

Git-related

git-lfs

BGF Repo-Cleaner (An alternative to git filter-branch)

CocoaPods being bit by Git shallow clones

Scaling git at Atlassian with Atlassian Stash

Why Google Stores Billions of Lines of Code in a Single Repository

Git at Google: Making Big Projects (and Everyone Else) Happy, Dave Borowitz - Git Merge 2015

Facebook employees asking about scaling Git

Other

Scaling Mercurial at Facebook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment