SeanPlusPlus
SeanPlusPlus

Reputation: 9053

Using the Node GitHub API to clone a remote repo locally

I am using the Node GitHub API to connect to a repo on GitHub.

And I can successfully fetch the refs of my remote repo:

const dotenv = require('dotenv')
const GitHub = require('github-api')

dotenv.config()

const api = process.env.GITHUB_URL
const token = process.env.GITHUB_TOKEN
const gh = new GitHub({ token }, api)
const owner = process.env.GITHUB_REPO_OWNER
const name = process.env.GITHUB_REPO_NAME
const repo = gh.getRepo(owner, name)
const branch = 'master'
const ref = `heads/${branch}`
repo.getRef(ref).then((response) => {

  // This works!!!
  console.log(response)
})

Now I would like to clone the contents of this repo to /tmp.

How do I do this? Thanks!!!

Upvotes: 1

Views: 121

Answers (1)

JDB
JDB

Reputation: 25875

The Node GitHub API is for interacting with the GitHub API... which doesn't include cloning locally because GitHub can't do that for you.

What you can do is install git locally then issue a git clone command, either through a terminal interface or through a purpose-made API.

Upvotes: 2

Related Questions