Skip to content

Instantly share code, notes, and snippets.

@muath-ye
Created February 1, 2025 04:33
Show Gist options
  • Save muath-ye/5d0e5257dce3cac5aeb2e524c75c6225 to your computer and use it in GitHub Desktop.
Save muath-ye/5d0e5257dce3cac5aeb2e524c75c6225 to your computer and use it in GitHub Desktop.

I want to clone phpmyadmin from github but it has more than 100k commits which makes it very large in storage size , so I need to clone it from github with only last version I don't care about commits history I only need to be able to check for updates

You can perform a shallow clone to retrieve only the latest snapshot of the repository (i.e. just the most recent commit) without the full commit history. This can save both time and disk space. To do so for phpMyAdmin, run:

git clone --depth 1 https://github.com/phpmyadmin/phpmyadmin.git

Explanation

  • --depth 1: This option tells Git to clone only the latest commit for each branch, creating a shallow clone without the complete history.

  • Repository URL: Replace the URL with your desired protocol (HTTPS or SSH). For example, using SSH:

    git clone --depth 1 [email protected]:phpmyadmin/phpmyadmin.git

Updating a Shallow Clone

If you want to check for updates later, you can update your shallow clone with:

cd phpmyadmin
git pull --depth 1

This command fetches only the latest commit from the remote repository and updates your working tree.

Additional Notes

  • Branch Selection: If you need to clone a specific branch (for example, if phpMyAdmin uses a branch other than the default), use the --branch option. For example:

    git clone --depth 1 --branch release https://github.com/phpmyadmin/phpmyadmin.git
  • Limitations: Shallow clones do not contain full history, so operations that require more history (like detailed blame information or advanced rebasing) might not work as expected. However, for simply getting the latest version and checking for updates, a shallow clone is usually sufficient.

Using the above commands, you can clone phpMyAdmin without downloading the full 100k+ commit history while still being able to update your local repository with the latest changes.

I need the latest tag

You can perform a shallow clone using only the commit pointed to by the latest tag. There are two approaches:


Option 1: Manually Specify the Latest Tag

If you already know what the latest tag is (for example, let's assume it’s RELEASE_5_2_1), you can run:

git clone --depth 1 --branch RELEASE_5_2_1 https://github.com/phpmyadmin/phpmyadmin.git

This command does the following:

  • --depth 1: Clones only the latest commit.
  • --branch RELEASE_5_2_1: Checks out the commit referenced by that tag.

Option 2: Automatically Determine the Latest Tag

If you’d prefer not to look up the latest tag manually, you can use GitHub’s API to fetch it. For example:

# Get the latest tag name from GitHub's API
LATEST_TAG=$(curl --silent "https://api.github.com/repos/phpmyadmin/phpmyadmin/releases/latest" | \
             grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

# Use that tag to perform a shallow clone
git clone --depth 1 --branch "$LATEST_TAG" https://github.com/phpmyadmin/phpmyadmin.git

Explanation:

  • The first command uses curl to fetch the latest release information from GitHub and extracts the value of "tag_name".
  • The second command clones the repository with a depth of 1 (i.e., only the commit pointed to by the latest tag).

Notes

  • Shallow Cloning:
    Using --depth 1 ensures you get only the snapshot of that tag without the full commit history. This minimizes disk space usage.

  • Updates:
    Since you’re cloning only one commit, if you want to check for a new release later, you’ll need to run the script again (or manually look up the new tag) and perform another shallow clone.

Using one of these methods, you can clone phpMyAdmin with just the latest tag’s code while keeping the storage footprint low.

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