Git clone to home directory with Powershell

34,385

That is strange. You could create the directory first, then use tab completion: C:\> mkdir ~/example C:\> git clone https://github.com/user/example.git ~/ex<[Tab]> C:\> git clone https://github.com/user/example.git C:\Users\Josh\example

or use the $HOME variable: C:\> git clone https://github.com/user/example.git $HOME/example

Share:
34,385

Related videos on Youtube

jost21
Author by

jost21

I'm an EE engineer, full stack web developer, open source advocate and tech enthusiast.

Updated on September 18, 2022

Comments

  • jost21
    jost21 over 1 year

    I used to work with cmd.exe on Win 10, but recently switched to Powershell.
    With cmd.exe both

    cd %USERPROFILE%\example 
    

    and

    git clone https://github.com/user/example.git %USERPROFILE%\example  
    

    work like intended. Since %USERPROFILE% does not work in Powershell, I use ~ instead.

    However, when I'm for instance in C: and enter the command cd ~/example in Powershell, I will end up in the folder C:\Users\JohnDoe\example (as intended).

    But when I run

    git clone https://github.com/user/example.git ~/example
    

    the repo gets cloned not to my home directory, but to C:\~\example.

    Is there a way to use ~ with the git clone command in Powershell?

    • user364455
      user364455 about 6 years
      git clone https://github.com/user/example.git $ExecutionContext.SessionState.Path.GetUnresolvedProviderPat‌​hFromPSPath('~/examp‌​le')
    • SimonS
      SimonS about 6 years
      or you just use $env:userprofile instead of %userprofile%
    • jost21
      jost21 about 6 years
      Thank you! Although $ExectionContext.... would take even more typing than just the normal path ;) I guess I will go with $env:userprofile for now, but it would be nice if ~ works in all cases
    • jost21
      jost21 about 6 years
      I assume this is because of git, or is the culprit Windows/Powershell?
    • SimonS
      SimonS about 6 years
      why would you need to use ~ when $env:userprofile works as intended?
    • SimonS
      SimonS about 6 years
      if you really need it, you can use $((resolve-path ~\Example).Path)
    • jost21
      jost21 about 6 years
      I don't need to use ~, it would just be nice if it worked (since it already partially works). And I'm used to it on my linux machine