Search code examples
gitgithubcompareclone

Validate local GIT repository clone is sourced from master GitHub repository


Is there a way to compare local clone of a GitHub repository to a repository in GitHub which is effectively the master repository to confirm that the local clone is a sub of the GitHub repository?


Solution

  • Because of the nature of git (last commit implies the entire history of that branch), you can validate it by comparing SHA1 of last commit to a credible repository's one.

    A simple shell code snippet can be like this (assuming you are only interested in master branch):

    if [ $(git rev-parse master^{commit}) == "<official sha1>" ]; then
        echo "Good"
    else
        echo "Bad"
    fi