Skip to content

Instantly share code, notes, and snippets.

@PatelUtkarsh
Last active May 9, 2022 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatelUtkarsh/60419645214198c30ed2f124afe698fe to your computer and use it in GitHub Desktop.
Save PatelUtkarsh/60419645214198c30ed2f124afe698fe to your computer and use it in GitHub Desktop.
Git cheat sheet shallow clone

All i know about shallow clone

Usecases:

  • For all readonly purpose this works great.
  • For big repo like linux project, mozilla firefox or WordPress like project it's really boring to wait for git to fetch all refs since we rearely needs all refs (if you know you're not gonna need).
  • You can contribute even after shallow clone but it works only in somecases mentioned below.

Fetch only one commit

git clone -b master git_url --depth 1

If you need to update cloned repo with --depth=1

git fetch origin master:master --depth 1
# OR 
git pull origin master --depth=1

Fetch all tags

git fetch --tags --depth=1

You can contribute using shallow commmit, As long as your commit history having all commits it needs to refer.

In case if you need all commits back you can always do

git fetch --unshallow

--unshallow will fetch all refs so it doesn't work well with branch fetch, meaning you can't chckout new branch from master and add some 10 commits on new branch and expect --unshallow to fetch those 10 commits only.

Contribute with --depth=1

You can fetch all branch you need as describe above, Now you can create new branch and from existing one and add commits on top and it should work as long as you're the only one adding the commits. Assuming you're not merging/rebasing that branch with base branch. In such case you need to do unshallow.

@jinalskothari
Copy link

Nice!

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