githug (version 0.0.0.9000)

git_init: Create a new Git repository

Description

Create a new Git repository or re-initialize an existing one, similar to git init.

Usage

git_init(path = ".")

Arguments

path
Where to create the new Git repo. Defaults to current working directory. If the path doesn't exist, it will be created via dir.create(path, recursive = TRUE).

Value

Path to the associated Git repo.

Details

Will bad things happen if you git_init() in a directory that is already a Git repo? No, it's fine! To quote the git-init man page, "running git init in an existing repository is safe. It will not overwrite things that are already there". A legitimate reason to do this is to pick up a new Git template, a topic which newcomers can safely ignore.

git_init() will not create a Git repo in a subdirectory of an existing Git repo. The proper way to do this is via Git submodules, which is beyond the current scope of the package.

Examples

Run this code
repo <- git_init(tempfile("git-init-example-"))

## switch working directory to the repo
owd <- setwd(repo)

## Config local user and make a commit
git_config(user.name = "thelma", user.email = "thelma@example.org")
write("I don't ever remember feeling this awake.", "thelma.txt")
git_commit("thelma.txt", message = "thelma is awake")

git_history()

setwd(owd)

Run the code above in your browser using DataLab