0

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?

  • git clone https://github.com/user/example.git $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('~/example') – PetSerAl Apr 24 '18 at 13:55
  • or you just use $env:userprofile instead of %userprofile% – SimonS Apr 25 '18 at 6:16
  • 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 – josh21 Apr 25 '18 at 7:46
  • I assume this is because of git, or is the culprit Windows/Powershell? – josh21 Apr 25 '18 at 7:51
  • why would you need to use ~ when $env:userprofile works as intended? – SimonS Apr 25 '18 at 10:02
0

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.