A cmd script to run posh-git
Not to be confused with the git command git-shell
In this demo, I'm using Hyper instead of PowerShell
GitHub for Windows used to ship with a shortcut called Git Shell, which would launch PowerShell with the posh-git module. However, it no longer does, and there are no plans to do so in the future. I wrote this couple of scripts to create a command line shortcut to run posh-git, replicating the Git Shell experience (although without the physical start menu tile). It does however, allow for loading posh-git to an existing console.
-
Git must be installed and available via the PATH environment variable
- Check that git is accessible from PowerShell by executing
git --versionfrom PowerShell - If git is not recognized as the name of a command, verify that you have Git installed
- If Git is not installed, download it from git-scm.com/download/
- Check that git is accessible from PowerShell by executing
-
Posh-git must be installed
- If you have previously installed the old version of GitHub for Windows, it will be in the
%LOCALAPPDATA%\GitHubfolder- Open File Explorer and type
%LOCALAPPDATA%\GitHub - One of the folders will be called
PoshGit_XXXXXXXXXXXXXXXwith a log string of alphanumerics. Keep this folder open for now.
- Open File Explorer and type
- If not, go to the posh-git repo and follow the installation instructions
- If you have previously installed the old version of GitHub for Windows, it will be in the
-
Get the scripts. Either:
- Download the two scripts
git-shell.cmdandgit-shell-ps.ps1to a folder called "git-shell" in your user directory (or a custom location) - Or cd to your user directory (or a custom location) and clone the repo there. You should then delete
README.md,LICENCEanddemo.gif.
- Download the two scripts
-
Right click
git-shell-ps.ps1and clickEdit- In the line
Import-Module $env:LOCALAPPDATA\GitHub\PoshGit_XXXXXXXXXXXXXXXXXXXX\posh-git.psm1, change the filepath to your posh-git installation - Set the default location to navigate to when
git-shellis called without the parameter-hereby changing the linecd ~\GitHub\as appropriate. If you want to remain in the current directory whengit-shellis called, delete the if-block.
- In the line
-
Add the git-shell folder to your PATH
- In Windows settings, search for "System environment" and click
Edit the system environment variables - Click the
Environment Variables...button near the bottom - Under either User variables or System variables, click on the
Pathvariable and then clickEdit... - Click
Newand type in the location of yourgit-shellfolder (e.g.,%USERPROFILE%\git-shell) - Click
Oketc.
- In Windows settings, search for "System environment" and click
> git-shell
Loads git-shell and navigates to your default folder (~\GitHub\ if you haven't changed it)
> git-shell -here
Loads git-shell in the current directory.
To change this behaviour, edit git-shell-ps.ps1. Do not edit git-shell.cmd unless you want to extend it (in which case why not create a fork of this repo).
> exit
Exits the session and returns to the last point before calling git-shell
If it keeps asking for a password to push changes to GitHub while using git, check out Git Credential Manager for Windows

