How to use git to get just the latest revision of a project?

Question

I don't want to clone the full repository and I'm not going to be submitting patches. I do want to easily get new revisions in the future.

I have tried using git clone, but this creates a copy of the entire repository (huge file size) and tracking changes makes the disk space even bigger (100mb of files now takes up over 2gb).

Is this possible?

Answer

Use git clone with the --depth option set to 1 to create a shallow clone with a history truncated to the latest commit.

For example:

git clone --depth 1 https://github.com/user/repo.git

To also initialize and update any nested submodules, also pass --recurse-submodules and to clone them shallowly, also pass --shallow-submodules.

For example:

git clone --depth 1 --recurse-submodules --shallow-submodules https://github.com/user/repo.git

How do I rename both a Git local and remote branch name?

Export a stash to another computer