% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linkGitHub.R
\name{linkGitHub}
\alias{linkGitHub}
\title{Link study directory to GitHub repository}
\usage{
linkGitHub(
  directory,
  repository,
  organisation = NULL,
  private = TRUE,
  description = NULL
)
}
\arguments{
\item{directory}{Path to study directory}

\item{repository}{GitHub repository name (will be sanitised if needed)}

\item{organisation}{GitHub organisation name. If NULL (default), creates repo
under your personal account}

\item{private}{Logical. If TRUE (default), creates a private repository}

\item{description}{Repository description. If NULL, auto-generated from directory name}
}
\value{
GitHub repository URL (invisibly)
}
\description{
Creates a new GitHub repository and connects it to an existing study directory.
Initializes git, creates .gitignore, commits all files, and pushes to GitHub.
}
\section{Requirements}{

\itemize{
  \item \strong{GitHub authentication}: Set up via GITHUB_PAT, gh CLI, or git credentials
  \item \strong{R package 'gh'}: Install with \code{install.packages("gh")}
  \item \strong{R package 'gert'}: Install with \code{install.packages("gert")}
}
}

\section{Authentication}{

This function needs credentials for both:
\itemize{
  \item \strong{GitHub API access}: used by \code{gh} to check your account and create the repository
  \item \strong{Git transport authentication}: used by \code{gert} to push the local repository to GitHub
}

Recommended setup:
\itemize{
  \item \strong{GITHUB_PAT environment variable}: recommended for HTTPS authentication and works for both GitHub API calls and Git pushes to GitHub
  \item \strong{Stored Git credentials}: credentials in your OS credential store or Git credential helper can also work for both the API and push steps
  \item \strong{gh CLI}: may help set up GitHub authentication, but you may still need Git credentials available for the final push
  \item \strong{SSH}: supported when your remote/auth setup is configured accordingly
}

To create a Personal Access Token (PAT):
\enumerate{
  \item Visit \url{https://github.com/settings/tokens}
  \item Generate a token with \code{repo} scope
  \item Set for current session: \code{Sys.setenv(GITHUB_PAT = "your_token_here")}
  \item Or add to .Renviron: \code{GITHUB_PAT='your_token_here'} and restart R
}
}

\examples{
\dontrun{
library(OmopStudyBuilder)
library(here)

# Authenticate (choose one method):
# 1. Set GITHUB_PAT for current session
Sys.setenv(GITHUB_PAT = "your_token_here")
# 2. Or use gh CLI: gh auth login

# Create repo under personal account
linkGitHub(
  directory = here::here(),
  repository = "my-omop-study"
)

# Create repo under organisation
linkGitHub(
  directory = here::here(),
  repository = "diabetes-study",
  organisation = "oxford-pharmacoepi",
  private = TRUE
)
}
}
