func isInsideGitWorkTree() bool {
	_, err := git("rev-parse", "--is-inside-work-tree")
	if err != nil {
		return false
	}
	return true
}
Check is inside work tree in git repository
package main
import (
	"bytes"
	"io/ioutil"
	"os/exec"
	"regexp"
	"strings"
	"syscall"
)
func hasGitCommand() bool {
	_, err := exec.LookPath("git")
	return err == nil
}