Git clone to home directory with Powershell
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
Related videos on Youtube
jost21
I'm an EE engineer, full stack web developer, open source advocate and tech enthusiast.
Updated on September 18, 2022Comments
-
jost21 over 1 year
I used to work with
cmd.exe
on Win 10, but recently switched to Powershell.
Withcmd.exe
bothcd %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 commandcd ~/example
in Powershell, I will end up in the folderC:\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 about 6 years
git clone https://github.com/user/example.git $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('~/example')
-
SimonS about 6 yearsor you just use
$env:userprofile
instead of%userprofile%
-
jost21 about 6 yearsThank 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 about 6 yearsI assume this is because of git, or is the culprit Windows/Powershell?
-
SimonS about 6 yearswhy would you need to use
~
when$env:userprofile
works as intended? -
SimonS about 6 yearsif you really need it, you can use
$((resolve-path ~\Example).Path)
-
jost21 about 6 yearsI 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
-