Reputation: 8163
git rev-parse
has an option --is-shallow-repository
to check if a sandbox is a shallow clone. However, I would like to check if the repository was cloned by --single-branch
.
I know it is possible to parse the git config remote.origin.fetch
result by myself. However, this is quite annoying and I do not know how stable the fetch value is. I would like to know if there a canonical way to determine this.
Upvotes: 0
Views: 247
Reputation: 487883
A clone could switch from being a single-branch clone to being a multi- or all-branch clone (using git remote set-branches
), or vice versa; in this case, the initial state is lost and only the current state is available. So it's not possible to find out what the state was at the time the repository was cloned. But usually that's not very interesting: what you want to know is the state right now, for which your git config --get-all remote.origin.fetch
is probably the right answer. If this outputs more than one line, you have a multi-branch (but perhaps not full) clone; if it outputs a single line, and the single line matches the default, you have a standard clone; otherwise you have a single or multi-branch clone, probably not full.
(This assumes the remote name is origin
; substitute in the correct name as necessary.)
(Note that this is the same as the --is-shallow-repository
test, which tests the current state, not the initial clone state, in case you have run git fetch --unshallow
.)
Upvotes: 1