Installation of git-lfs on Ubuntu RPi2 (armf)

Unfortunately, the standard way to install git-lfs doesn’t work on RPi2. But there is simple workaround:

# install go
sudo apt-get install golang
# you may want to grab a coffee at this stage... 😉 

# get git-lfs from github
sudo -i
mkdir /root/gocode
export GOPATH=/root/gocode
go get github.com/github/git-lfs
cp gocode/bin/git-lfs /usr/bin

Reducing the size of large git repository

The github repository of #NGSchool website has grown to over 5GB. I wanted to reduce the size & simplify this repository, but this task turned out to quite complicated. Instead, I have decided to leave current repo as is (and probably removed it soon) and start new repo for existing version. I could do that, as I don’t care about version earlier than the one I’m currently using. This is short how-to:

  1. Push all changes and remove .git folder
  2. git push origin master
    rm -rI .git
    
  3. Rename existing repo
  4. Settings > Repository name > RENAME

  5. Start new repository using old repo name
  6. Don’t need to create any files as all already exists.

  7. Init your local repo and add new remote
  8. git init
    git remote add origin git@github.com:USER/REPO
    
  9. Commit changes and push
  10. git add --all . && git commit -m "fresh" && git push origin master
    

Doing so, my new repo size is below 1GB, which is much better compared to 5GB previously.

Working with large binary files in git

Git is great, there is no doubt about that. Being able to revert any changes and recover lost data is simply priceless. But recently, I have started to be concerned about the size of some of my repositories. Some, especially those containing changing binary files, were really large!!!
You can check the size of your repository by simple command:

git count-objects -vH

Here, git Large File Storage (LSF) comes into action. Below, I’ll describe how to install and mark large binary files, so they are not uploaded as a whole, but only relevant chunks of changed binary file is uploaded.

  1. Installation of git-lfs
  2. # add packagecloud repo
    curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
    
    # install git-lsf
    sudo apt-get install git-lfs 
    
    # end enable it
    git lfs install
    
  3. Marking and commiting binary file
  4. # mark large binary file
    git lfs track some.file
    
    # add, commit & push changes
    git add some.file
    git commit -m "some.file as LSF"
    git push origin master
    

Pushing to multiple github repositories

Today I’ve faced problem with syncing two github repositories. Yes, I know, I shouldn’t keep two, but sometimes it’s difficult to avoid. Anyway, the problem is super easy to solve. It’s enough to edit `.git/config` by adding new remote:

[remote "Origin"]
    url = git@github.com:user1/repo1.git
    url = git@github.com:user2/repo2.git

Of course, more than two repos can be added. Then, after next push all repositories will be synced.

git push Origin master

Everything up-to-date

Counting objects: 61, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (61/61), done.
Writing objects: 100% (61/61), 5.73 KiB | 0 bytes/s, done.
Total 61 (delta 41), reused 0 (delta 0)
To git@github.com:user2/repo2.git
   8b97528..8aed8c2  master -> master

Inspired by ruiabreu.