Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git to get just the latest revision

Tags:

git

I want to track a project that uses git. I don't want to clone the full repository and the full history, I just want the latest revision, and I want to be able to update to new revisions from the remote project.

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).

I'm not going to be submitting patches, and I don't need the history. I just want the latest version like in subversion.

Is this possible in git?

like image 794
yuit Avatar asked Jul 30 '09 23:07

yuit


People also ask

How do I pull the latest code from git in Vscode?

Set up from installation and pullEnter “github” in the Search field, click “Github Pull Requests”, and click “Install”. When installation is completed click “Reload”. Open the command palette and search for git clone and execute it. Clone the repository of github you want to use into the appropriate folder.

What's the difference between git fetch and git pull?

Git Fetch is the command that tells the local repository that there are changes available in the remote repository without bringing the changes into the local repository. Git Pull on the other hand brings the copy of the remote directory changes into the local repository.


1 Answers

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 
like image 141
Greg Hewgill Avatar answered Oct 10 '22 11:10

Greg Hewgill