Description Usage Arguments Details Value Examples
This function adds a file in a repository in GitHub by creating a new commit
on the specified branch. If the branch does not already exist a parent
commit must be specified and a new branch is created from it. If the file
already exists create_file()
throws an error.
1 2 3 4 5 6 7 8 9 10 11 | create_file(
content,
path,
branch,
message,
repo,
parent,
author,
committer,
...
)
|
content |
(string) The content of the file specified as a single string. |
path |
(string) The path to create the file at, within the repository. |
branch |
(string) The name of the branch to make the new commit on. |
message |
(string) The commit message. |
repo |
(string) The repository specified in the format: |
parent |
(string, optional) If creating a new branch the the parent commit must be specified as either a SHA, branch or tag. |
author |
(list, optional) A the name and email address of the user who wrote the changes in the commit. |
committer |
(list, optional) A the name and email address of the user who created the commit. |
... |
Parameters passed to |
The author
and committer
arguments are optional and if not supplied the
current authenticated user is used. However, if you want to set them
explicitly you must specify a named list with name
and email
as the
elements (see examples).
Note: The GitHub API imposes a file size limit of 1MB for this request. For
larger files use the upload_files()
function.
For more details see the GitHub API documentation:
create_file()
returns a list of the commit properties.
Commit Properties:
sha: The commit SHA.
message: The commit message.
author_name: The author's name.
author_email: The author's email address.
committer_name: The committer's name.
committer_email: The committer's email address.
tree_sha: The SHA of the file tree.
parent_sha: The commit SHA of the parent(s).
date: The date the commit was made.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ## Not run:
# Create a new file on the main branch
create_file(
content = "# This is a new file\\n\\n Created by `create_file()`",
path = "new-file.md",
branch = "main",
message = "Created a new file with create_file()",
repo = "ChadGoymer/githapi"
)
# Create a new file on a new branch
create_file(
content = "# This is a new file\\n\\n Created by `create_file()`",
path = "new-file.md",
branch = "new-branch",
message = "Created a new file with create_file()",
repo = "ChadGoymer/githapi",
parent = "main"
)
# Create a new file on the main branch specifying an author and committer
create_file(
content = "# This is a new file\\n\\n Created by `create_file()`",
path = "new-file.md",
branch = "main",
message = "Created a new file with create_file()",
repo = "ChadGoymer/githapi",
author = list(name = "Bob", email = "bob@acme.com"),
committer = list(name = "Jane", email = "jane@acme.com")
)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.