Search code examples
node.jsgithubpullorganization

How to pull a private GitHub repository (organisation) with node.js


I have a private GitHub repository that is owned by an organization. I want to pull the repository automatically after pushing to it. The webhook is already working, and I receive the event, but now I am stuck at the part where I pull the repository.

How can I pull a private GitHub repository, that is owned by an organization, using a single command, or using a package.

I have done research on this subject, however, I was unable to find a solution.


Solution

  • const util = require('util');
    const exec = util.promisify(require('child_process').exec);
    
    (async () => {
       const { stdout, stderr } = await exec('git pull https://<token>@github.com/<username>/your_repo.git', {cwd: '/path/to/your_repo'})
       console.log(stderr, stdout)
    })()
    

    You can generate a personal access token with clone and pull permission from here: https://github.com/settings/tokens