Git Command – How to Execute Git Command Without Interactive Console

gitpowershell

I am new to Git, first time I am using it.

I installed it, in my "program files" folder there two executables there:

C:\Program Files\Git\git-bash.exe
C:\Program Files\Git\git-cmd.exe

Just to confirm things are in working order, I managed to clone a repository to a local folder using git-cmd, by directly executing it in File Explorer, then in that new cmd window:

cd "c:\temp"
git clone https://github.com/SomeName/SomeRepo

Of course I would like to do this in my PowerShell envoiroment in Windows Terminal. I have tried:

. "C:\Program Files\Git\git-cmd.exe" clone "https://github.com/SomeName/SomeRepo"

All that happens is some CMD window flashes, closes, then my PowerShell prompt is replaced with what looks to be a CMD style promt.

I am looking to stay inside my powershell envoiroment and simply carry out a single "Git" command, clone the repo to the current directory.

I also tried this with git-bash, this opens its own window:

.  "C:\Program Files\Git\git-bash.exe" clone https://github.com/SomeName/SomeRepo

I tried using the comd flag /c with git-cmd, no luck:

. "C:\Program Files\Git\git-cmd.exe" /c clone "https://github.com/SomeName/SomeRepo"

I was not expecting to go down a rabbit hole at this late hour, please send help.

Best Answer

Neither of these executables is Git. git.exe is in the bin folder.

git-bash.exe is a utility to launch Git Bash, a minimal UNIX-y environment with a Bash shell preconfigured to use Git, with tab completion and branch names in the prompt and whatnot.

git-cmd.exe is somewhat similar, but launches a standard Windows Command Prompt instead. This is useful because you can decide to not have git.exe in %PATH%, making these special shell launchers your only option. (Using the full path is also always possible.)

If you did decide to have Git in %PATH% when you installed it, you do not need to worry about where git.exe is. Just use Git commands.

Plain git.exe is also fine for use in PowerShell. Posh-Git is not required.

Related Question