Keith Adler
Keith Adler

Reputation: 21178

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?

Upvotes: 1

Views: 83

Answers (1)

dyng
dyng

Reputation: 3054

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

Upvotes: 1

Related Questions