question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

To pull the cloned remote branch by using url [where the repo saved] from other directory

See original GitHub issue

I used code to clone like this from the simple-git npm package

var gulp=require('gulp');
 const simpleGit=require('simple-git');
 const git=simpleGit();
 gulp.task('d',  async function()
 {
 await git.clone( repository ,localfoldername,{'--branch': branch name})
 shell.cd(localfoldername)
 await git.pull()
 }

While running the gulp task in a terminal in visual studio code as ‘d:/default> gulp d’

cloning is done with a local folder But pull will not occur Because the gull command worked on ‘d:/default>’ where there will remote repository ‘origin’ was saved It was saved in ‘d:/default/localfolder’ there I need to pull Please suggest to me how to overcome this, I am new to both gulp and git

where there is an option to move to remote branch URL then clone

or other suggestions

git

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
steveukxcommented, May 10, 2021

The git.exec method (as documented .exec(handlerFn) | calls a simple function in the current step) is a way to call a function, so you can be sure the function is executed between any other chained methods (though in your example you don’t chain methods as you just use the one git instance and await each time).

To call out to a shell command like npm install etc, you would need to use something like child_process.exec - documentation for this is on the node website at https://nodejs.org/dist/latest-v14.x/docs/api/child_process.html#child_process_child_process_exec_command_options_callback

For example:

const {exec} = require('child_process');
const repoDir = require('path').join(__dirname, 'new');

exec('npm install', { cwd: repoDir });
0reactions
karthiganesh476commented, May 17, 2021

Hi,

  • I want to store the output of simple-git command in variable
  • ex: var current_branch= ‘git.branch()’
  • [ git branch -> if the branch= development then current_branch =“development”]
const gulp = require('gulp');
 const simpleGit = require('simple-git');
 var argument = require('yargs').argv;
 var shell=require("shelljs");
 var fs=require('fs')
 gulp.task('work', async function (done) {
   const git = simpleGit();
   const repoDir = require('path').join(__dirname,argument.local_folder);
   if(!fs.existsSync(repoDir))
   {
     await git.clone(argument.repository, argument.local_folder, {'--branch':argument.branch});
     await git.cwd(repoDir);
   }
   else
   {
   await git.cwd(repoDir);
    let current_branch;
    current_branch = `git.branch()`
     console.log(current_branch);
     let cloning_branch =argument.branch;
     console.log(cloning_branch);
    if(current_branch != cloning_branch)
    {
      console.log("checkout............")
      await git.checkout(argument.branch)
      await git.clean(['f','d','x'])
      await git.pull()
    }
    else
    {
      console.log("Clean........................")
     await git.clean(['f','d','x'])
     await git.pull()
    }

   }
 done()
 });
Read more comments on GitHub >

github_iconTop Results From Across the Web

git clone | Atlassian Git Tutorial
Git clone is a Git command line utility used to target and create a copy of the target repository. Learn extended configuration options...
Read more >
Git Clone Branch – How to Clone a Specific Branch
With this, you fetch all the branches in the repository, checkout to the one you specified, and the specific branch becomes the configured...
Read more >
How do I clone a Git repository into a specific folder?
go to the directory where you want to clone the repo. (don't run git init command inside that directory) · simply run the...
Read more >
Easily Perform Git Checkout Remote Branch [Step-by-Step]
As an existing repository exists, you are ready to get started. Follow along below to clone the remote repository to a local folder....
Read more >
git-clone Documentation - Git
Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found