Ahmad Awais

NAVIGATE


SHARE


Shallow Clone a Large Git Repository Quickly

Ahmad AwaisAhmad Awais

Say you have a large git repository say 1 GB or even bigger. It may have a lot of branches and a long history. You now want to clone it to make some changes and create a pull request. Cloning it in its entirety with git clone would be a bad idea. Instead, do this:

git clone -b <branch> <url> --depth=1

A practical example would be:

git clone -b master https://github.com/gatsbyjs/gatsby --depth=1

The giant 735.03 MB Gatsby repository, cloned this way is about 680 MB in size. I read that Jira is 677MB, with the working directory being another 320MB, when you clone this way.

Explanation:#

You can work this magic when pulling down the code as well:

git pull --rebase origin <branch> --depth=1

A practical example would be:

git pull --rebase origin master --depth=1

That’s about it. You are now shallow cloning and pulling your git repo. It doesn’t make that huge of an impact but I like to stay minimal as far as I can.

Use your code for good.

👨‍🏫 Edutainer at VSCode.pro 🎩 An award-winning open-source engineer and developer advocate 🦊 Google Developers Expert for web 🌳 Node.js foundation Community Committee member ✌️ Author of various open-source dev-tools and software libraries used by millions of developers worldwide ⓦ WordPress Core Developer 📣 TEDx Speaker 🙌 Leading developers and publishing technical content for over a decade 😂 Self-confessed tech comedian cracking silly jokes in the JavaScript web and cloud communities 💜 Loves his wife (Maedah) ❯ Learn more about Awais ↣

Say 👋 on Twitter @MrAhmadAwais | Subscribe to the Developers Takeaway!

📨

TheDevTakeaway: Developers' Newsletter!

Takeaway my professional opinion about Open Source, JavaScript/Cloud, Full Stack Development, building a business, growing a family, and everything in between! Delivered to your inbox once a month. 🤣 I'm even funny some times. 👻 I hate spam! Pinky Promise!