Why you should not push binary files to git? And what to do if you do ?

vegeta
2 min readMar 19, 2019

Today, I’d like to show you one of most common problems when using git and how to solve that problem.

Which version control system is right for you? I think that’s Git.
We all understand the advantages of using Git so I will not mention What is git? or How git works? in this article.

First you need to remember that Git can not diff birnay file. It will upload entiry file into repository and will store its pretty much forever.

It will also store every single version of every single binary file within the repository. So , if you clone that repository, you’ll need download all of them, all of version of that binary file. So that will make cloning repository become as slow as tortoise.
If you have unlimited bandwidth and unlimited storage. Okay, you like a boss . Go for it :). But I don’t recommend !

However, depends on project you have to use binary file for building or running project . The best idea I recommend you is to store binary files in separate version control system such as Dropbox, Google driver and use git only for code.

Now, what we have to do if we pushed binary file into git already ?
Don’t worry, I’ll tell you how to solve this problem?

  1. Delete files and all of its history in git
  2. Force push to git

So, let’s go first step: Delete files and its history
In order to delete files and history, you just execute below command:

After executed above command, if you see below log it is successfully.

Then, we have to push into remote git . We’re trying to re-write history of git so of course we must use git push -f .

If not, you will see the error:

That’s all !

Happy coding …

--

--