Search code examples
powershellregistrygit-clone

Windows FIle Explorer, add clone clipboard contents in context menu


Also see my Run Powershell.

My attempt is to implement the following work flow

  • in GitHub or anyother repo server copy the link to a repo
  • in Windows File explorer right click a folder eg D:\Projects to open the context menu.
  • select Clone here from the context menu to clone the copied repo in that folder.

I added this in registry

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\git-clone]
@="Clone here"

[HKEY_CLASSES_ROOT\Folder\shell\git-clone\command]
@="Powershell -NoProfile -Command \"git clone $(Get-Clipboard)\""

This does add a "Clone here" to the context menu and it clones but not in the directory right clicked but its parent directory.

How would I clone the repo in the directory right clicked?


Solution

  • Thanks to @keithmiller tip I found the solution

    The command that works is

    Powershell -NoProfile -Command "Set-Location -LiteralPath '%V' ; git clone $(Get-Clipboard)"
    

    And the registry entry can be created with the following .reg file:

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Directory\shell\git-clone]
    @="Clone here"
    
    [HKEY_CLASSES_ROOT\Directory\shell\git-clone\command]
    @="Powershell -NoProfile -Command \"Set-Location -LiteralPath '%V' ; git clone $(Get-Clipboard)\""
    

    I use Directory branch instead of Folder here as it probably only works in real file directories.