Set up a smoking Git shell on Windows

git github console shell 37 comments suggest edit

GitHub Desktop, the application formerly known as GitHub for Windows, is a streamlined GUI that makes it easy to contribute to repositories on GitHub.

GitHub Desktop Screenshot

At the same time, I often hear from people that they don’t need a GUI because they’re perfectly happy to use the command line. If you feel this way, that’s great! I love the command line too! Let’s be friends!

Even so, in a set of blog posts I plan to write, I hope to convince you that GitHub Desktop is one GUI application that augments and complements the Git command line in such a powerful way that you’ll want to integrate it into your GitHub workflow.

But for now, I’ll work to convince you that GitHub Desktop is the easiest, fastest, and best way to get the Git command line set up on a Windows machine and keep that installation up to date.

Installation

Installation is easy. Visit desktop.github.com and click the big blue button that says “Download GitHub Desktop.” We use ClickOnce to streamline the installation process.

Once you install, you’ll notice a GitHub icon and a Git Shell Icon on your desktop.

GitHub Desktop Icons

By default, the Git Shell shortcut launches PowerShell with Git set up. You can also launch the Git Shell from the Desktop GUI application by pressing the ~ key (or CTRL + ~ at any time such as when a text field has focus) or via the gear menu in the top right. Select the “Open in Git Shell” menu item.

Support for the ~ key to launch the shell was inspired by the 3D shooter Quake which uses that key to bring up the console within the game. Many thanks to Scott Hanselman for that idea.

Sane Defaults

We often mention that we install Git with “sane defaults.” What do we mean by that? Well, let me tell you an old joke first.

Q: How do you generate a random string? A: Put a Windows user in front of vi, and tell them to exit

I can’t take credit for this joke. The first instance I’ve found is on Twitter by Aaron Jorbin.

By default, Git sets vi as the default commit editor. Statistically speaking, that’s never the right answer for Windows users. GitHub Desktop sets your default editor (typically NotePad) as the default editor via the open source GitPad tool.

Also, GitHub Desktop sets itself up as the Git credential provider. That way, you can log into the app and we’ll handle the credential management when you push to or pull from GitHub using the Git command line. This is especially useful if you have two-factor authentication enabled (WHICH YOU SHOULD!) as we handle the 2fa dance on your behalf. There’s no need for messing around with personal access (OAuth) tokens.

Posh-Git

The other “sane default” is that we include Posh-Git (maintained by Keith Dahlby) with our installation.

When you launch the shell, you’ll notice that the Powershell window now has a Git enhanced prompt that displays your current branch name. Posh-Git provides tab completion within PowerShell for Git commands and Git data. For example, you can type git {TAB}, where {tab} is the TAB key, and it will complete with the first Git command (abort in this case). Keep pressing TAB to cycle through all the Git commands.

Likewise, if you type git checkout b{tab}, you can cycle through all branches in your repository that start with b.

Here is an animated gif that shows what it looks like to tab through all my repository’s branches.

Posh-Git Tab Expansion

PowerShell Configuration

One thing to note is that if you launch PowerShell via some other means other than our Git Shell shortcut or the Desktop application, our version of Git won’t be there. That’s because we install a portable version of Git that does not change any of your system settings.

You can add our version of Git to your PowerShell profile so it’s always there. Simply edit the PowerShell profile document: %UserProfile%\Documents\WindowsPowershell\Microsoft.Powershell_profile.ps1

Add this snippet to the file.

Write-Host "Setting up GitHub Environment"
. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")

Shell.ps1 contains the environment settings that the Desktop application uses when it launches the Git Shell.

You can also have your default profile load up Posh-Git if you haven’t already. Make sure this snippet comes after the previous one.

Write-Host "Setting up Posh-Git"
. (Resolve-Path "$env:github_posh_git\profile.example.ps1")

$env:github_posh_git is one of the environment variables that Shell.ps1 sets up.

The other thing to note is if you have already customized PowerShell with a profile, the Git Shell doesn’t load your existing PowerShell profile. We wanted to avoid conflicts with existing Posh-Git installs or whatever else you might have. To load your existing profile requires you to opt into this behavior. To do this, create a PowerShell script file named GitHub.PowerShell_profile.ps1. Desktop will execute this file, if it exists.

Desktop looks for this file in the same directory as your $profile script (typically %UserProfile%\Documents\WindowsPowershell\). I simply load my regular profile from that script.

Here’s the full contents of my GitHub.PowerShell_profile.ps1.

Write-Host "Setting environment for GitHub Powershell Profile"

$dir = (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
Push-Location $dir

. (Resolve-Path "$dir\Microsoft.Powershell_profile.ps1")

Pop-Location

Turbocharge the Shell with ConsoleZ

Hey, you’re an individual and you need to express that individuality. Nothing says “I’m boring” like the default blue PowerShell console (if you do always use the default, ignore what I just said. You might be the real noncomformist). I express my individuality with a fork of Console2 called ConsoleZ just like every one of my friends! If you have Chocolatey installed, you can run this command to install ConsoleZ:

chocolatey install ConsoleZ

Then in GitHub Desktop, go to the Tools menu (top right gear icon), select Options..., and find the section labeled Default Shell. Select Custom and enter the path to ConsoleZ. On my machine, that’s C:\Chocolatey\lib\ConsoleZ.1.15.0.15253\tools\Console.exe.

Default Shell

You’re not quite done yet. By default, ConsoleZ loads the Command shell. You’ll want to change it so it loads PowerShell.

  • Right-click in the main console and click Edit Settings.
  • Under Tabs, paste the path %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe into the “Shell” text box.

ConsoleZ Tab Settings

You’ll notice I got a little fancy and use the Git Shell icon for the tab. I put icon here (or use our Octocat App Icon) so you can download it and do the same if you’d like. I saved the icon to the %LocalAppData%\GitHub\icons directory and then pasted the path to the Icon in the Icon text box.

Customize ConsoleZ

That’s just enough to make ConsoleZ work with Desktop. But since you’ll spend a lot of time in the shell, let’s really turbo charge it. Here is a set of customizations adapted from Scott Hanselman’s Console2 blog post. I’ve made a few small tweaks in places to ensure that the customizations don’t interfere with the Git Shell functionality.

  • Under the Console tab, do not enter a value for the “Startup Dir” setting as Hanselman suggests. When you launch the Git Shell from the Desktop application, it will set the working directory to the currently selected repository’s working directory. If you set ConsoleZ’s startup directory, then that feature of Desktop is overridden. If you don’t care about this feature, by all means set a startup directory.
    • Under the Console tab, do play around with the Columns and Rows. I have mine set to 30 rows, and 80 columns.
  • Under Appearance More, hide the menu, status bar and toolbar.
  • Under Appearance Font, set the font to Consolas 15. Unlike Hanselman’s advice, do not change the font color. Posh-Git makes important use of color. Not to mention the output of many Git commands will use color to signify additions and deletions, for example. If you want to change the default font color, do it via your PowerShell profile or by hacking Posh-Git.
  • Under Appearance Transparency, Hanselman recommends setting Window Transparency to a nice conservative 40 for both Active and Inactive. I like setting Inactive to 80. Your mileage may vary.
  • Under Hotkeys, set “Group Tab” to something else like CTRL+ALT+T. This frees you up to change the “New Tab 1” hotkey to CTRL+T as God intended. You’ll have to click on the hotkey, then in the textbox, then type the hot-key you want AND press the Assign button for it to stick.
  • Under Hotkeys, change “Copy Selection” to Ctrl-C and “Paste” to Ctrl-V

Here’s what it looks like on my machine. You can see my background image poking through.

Customized ConsoleZ

Finally, one setting that makes ConsoleZ feel really badass to me is to go to Appearance Full Screen and check “Start in full screen”. I’ve been using this for a bit and it’s growing on me. Just remember, hit ALT+F4 or type exit to close it.

Updates

We put in a lot of work to ensure that GitHub Desktop silently and automatically updates itself. When we ship an update, you’ll see a subtle notification in the application (a little up arrow in the top right) that an update is available. Just restart the application to install the update.

Desktop updates also include updates to Posh-Git, the Git command line, and Git LFS. It’s convenient to have all of that updated for you automatically so you don’t have to track down each update individually.

We keep everything updated so you don’t have to.

Conclusion

With these customizations in place, you’ll have a really great Git command line setup that we’ll work hard to keep up to date so you don’t have to. In fact, we have a few updates coming up very soon! Follow this up with some of my Git aliases and you’ll really be smoking.

Be careful though, a setup like this communicates that you’re a Git Pro and everyone will start to bug you with their Git problems. Just remember, git reflog is your friend.

In some follow-up posts, I’ll demonstrate how this setup works really nicely in tandem with GitHub Desktop.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

37 responses

  1. Avatar for Dave Zych
    Dave Zych October 29th, 2015

    I've been using ConEmu recently and really like it. It includes tabbed navigation, ability to launch cmd, powershell and bash (and more if you want!) and is incredibly customizable. You should check it out if you haven't tried it yet!

    https://conemu.github.io/

  2. Avatar for Maris Krivtezs
    Maris Krivtezs October 29th, 2015

    I am using ConEmu and can't get it to work with private GitHub repositories. I have the same
    configuration in my profile.ps1 (except, I am checking if it's not VS Package Console):

    if (!$profile.Contains("NuGet_profile")) {
    . (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
    . (Resolve-Path "$env:github_posh_git\profile.example.ps1")
    }

    When I pull/push from the public repository - everything works fine. But with private repositories even on pull I get:

    Permission denied (publickey).
    fatal: Could not read from remote repository.
    Please make sure you have the correct access rights and the repository exists.

    git status seems to work fine and I get info from GitHub:

    Your branch is ahead of 'origin/master' by 11 commits.

    I can pull/push with default PowerShell console which is started from GitHub for Desktop.

    Another issue with ConEmu - autocomplete doesn't work. When I do: git check{tab} it does not complete the command. Same time I have nice colored status from Posh-Git.

    Any ideas what's missing in PowerShell configuration for ConEmu?

  3. Avatar for Thomas Levesque
    Thomas Levesque October 29th, 2015

    > We keep everything updated so you don't have to.

    Everything except Git, it seems ;). GitHub Desktop still installs Git 1.9.5 (a custom build, it seems), even though Git for WIndows 2.6.2 is available. Why is that?

    Regarding ConsoleZ, I'm not really convinced of the benefits if you're using Windows 10. The default console host has been greatly improved in WIndows 10, and now supports resizing, Ctrl-C/Ctrl-V for copy/paste, keyboard selection, transparency, etc

  4. Avatar for Jeroen Veldhuijzen
    Jeroen Veldhuijzen October 29th, 2015

    Was gonna say the same, Phil give it a try!

  5. Avatar for Bobo
    Bobo October 29th, 2015

    My only issue with github she'all is I can't pin to taskbar in win10 :( the weird explorer thing used to work in win8 but not in 10

  6. Avatar for Mitja Bezenšek
    Mitja Bezenšek October 29th, 2015

    Another happy conemu user here. Two other very useful things:
    1. Jump location: https://github.com/tkellogg...
    2. Not showing the full paths in the console: http://superuser.com/questi...

  7. Avatar for Matt Evans
    Matt Evans October 29th, 2015

    me too! Along with psReadLine for fancy syntax highlighting and more:

    http://www.hanselman.com/bl...

  8. Avatar for Mike Sprague
    Mike Sprague October 29th, 2015

    I would also recommend Cmder (especially if you're already familiar with ConEmu).

    It uses ConEmu (along with Clink enhancements) and is also fully portable. I keep a copy in Dropbox that I can open on any of my dev machines.

    I made the switch from ConEmu to Cmder about 2 months ago and highly recommend it.

    http://cmder.net/ | https://github.com/cmderdev...

  9. Avatar for Stuart Grassie
    Stuart Grassie October 30th, 2015

    I was going to mention this in the comments, but alas I was beaten to the punch:

    C:\dev\cs\proj [dev]> git --version
    git version 1.9.5.github.0

    I also agree completely about the default shell in Windows 10, and powershell seems much improved also.

  10. Avatar for Brett Baggott
    Brett Baggott October 30th, 2015

    I love these type of tips and tools posts/discussions. A lot of times, those that know take for granted that everyone knows such tips. And it's not just about having a cool looking console. These tweaks add up quickly to more productivity and more fun getting the job done. Thanks for sharing. Oh, and I love Github Desktop. Even though I do a lot of my git work via cli, Github Desktop is my "overview". It's what I tell anyone new to git to install first.

  11. Avatar for Christopher
    Christopher November 4th, 2015

    Agree with the recommendation of Cmder and also confused why it installs Git 1.x instead of 2.x?

  12. Avatar for Stefan
    Stefan November 6th, 2015

    You should give ConEmu (https://conemu.github.io/) a try, far more customizable ;)

  13. Avatar for Mykezero
    Mykezero November 7th, 2015

    Depending on your operating system, you may want to reconsider binding CTRL-C to copy selection if you want to be able to cancel commands (since binding CTRL-C to something else blocks this functionality).

  14. Avatar for Thomas Freudenberg
    Thomas Freudenberg November 9th, 2015

    In my installation of GitHub Desktop (3.0.7.1) posh-git is missing. According to TheLog.txt the last version of GitHub Desktop on my machine installing posh-git was 2.3.1.1. Was posh-git removed recently?

  15. Avatar for haacked
    haacked November 9th, 2015

    It wasn't removed. Try closing the app and make sure no other instances of GitHub.exe are running. Then launch it again. It should extract it. If not, contact our support team via https://github.com/support and we'll figure it out.

  16. Avatar for Thomas Freudenberg
    Thomas Freudenberg November 9th, 2015

    Thanks, I created an issue in github-beta/github-desktop :-)

  17. Avatar for Mads
    Mads November 30th, 2015

    Hi Phil.

    Now this article is about Windows and that's all fine. "Sadly" I'm doing a game in Unity3d currently for iPhone and is therefore on a Mac.

    Of cause I use Github Desktop (great app!) and everything is fine and working with two-step auth and all.

    The problem is, that yesterday I needed to go to the commandline, which is easy, to add and push some tags, as I have just created a release.

    But, I cannot push my tags to Github...it keeps asking for credentials and even whenI provide that, it fails, telling me that it's wrong - which it's not.

    Actually I cannot even do a pull or push, ask for credentials, which it wouldn't take.

    Error:
    remote: Invalid username or password.
    fatal: Authentication failed for 'https://github.com/Laumania/[REPO.NAME]

    So what am I doing wrong?

  18. Avatar for Thomas Levesque
    Thomas Levesque November 30th, 2015

    @Mads, you must provide a personal access token instead of your password:

    https://help.github.com/art...

  19. Avatar for Mads
    Mads November 30th, 2015

    Arh, thanks :)

    Was just confused, as it works perfectly on Windows, no password/username needed there at all in the commandline. Windows > OSX, but I know that (I'm a .NET dev ;))

  20. Avatar for haacked
    haacked November 30th, 2015

    Email support@github.com and they can sort this out.

  21. Avatar for Lukas Malkmus
    Lukas Malkmus January 5th, 2016

    Very nice. But I'm still in trouble. I would love to dump putty and pageant completely, and use ssh + ssh-agent. But I have no idea how to get ssh-agent running.

  22. Avatar for haacked
    haacked January 6th, 2016

    The GitHub Shell starts ssh-agent.exe for you.

  23. Avatar for Lukas Malkmus
    Lukas Malkmus January 6th, 2016

    Thanks, noticed that myself just minutes ago :)

  24. Avatar for Dustin Moris Gorski
    Dustin Moris Gorski January 8th, 2016

    I personally don't quite understand the use case of GitHub for Windows. It feels like there is a lot of development going into a tool which at the moment is a throw away application after 2 weeks.

    What do I mean by this? It is a great tool, but it has almost no features which are relevant for someone who truly works with Git as their source control. I feel like GitHub for Windows is the first tool a TFS/SVN .NET developer installs to get a familiar experience with Git, but once the developer starts serious business and learns how git works he/she will quickly realize that GitHub for Windows doesn't offer any of the things you would expect and uninstalls it two weeks later to replace it with the git shell or another GUI like smartgit or SourceTree.

    I personally think GitHub for Windows has so much potential and I would love to see it become more useful. Doesn't the team want to make the tool to something more than just a 5 minute toy?

  25. Avatar for Broliant
    Broliant January 24th, 2016

    ConEmu comes with a few useful util-scripts in the standard distribution, one of which enables displaying the git branch name plus basic branch stats in the command-prompt.

    You can enable it manually at any time by issuing the command "%ConEmuBaseDir%\GitShowBranch /i" although this may also need you to setup an environment variable that points to the location of git.exe/git.cmd on your machine... for example, you can do something like "setx ConEmuGitPath "D:\Home\Apps\Git\cmd\git.exe" - adjusted obviously for where git.exe is on your machine and you can check this using "where git" at the command prompt.

    Alternatively, if you have configured ConEmu with a custom CmdInit.cmd (also in the %ConEmuBaseDir%) then you can simply switch it on for every new command shell you open in ConEmu.

    The final result (with nicely coloured/colored text) will be something like:

    broliant@vmwin10 d:\Home\Broliant\Projects\project-001 [master +1 ~0 -0]

    It works really nicely. Give it a go. :)

  26. Avatar for James World
    James World January 27th, 2016

    Good use of source control requires expertise. DVCS source control concepts are not trivial. For me, there hasn't been a GUI to date for Git that has been better than the command line - and I am not a shell zealot by any stretch. However, there's a learning curve to reach command line mastery - not *because* it's a command line and not a GUI - but because the underlying concepts aren't trivial. However, you have to start somewhere, and a friendly GUI like GHfW or SourceTree can be a handy crutch while you are transitioning from a simpler world. Tab-completion and a decent diff tool give me all the UI I need. I think a lot of people end up in the same place - my team did, I just straw polled my team to double check - they really did all thank me in the end for forcibly uninstalling all their Git GUIs and making them use the command line. And it's had a very positive impact on the quality of our source repositories. So maybe GHfW is just fine as training wheels.

  27. Avatar for James Culbertson
    James Culbertson January 31st, 2016

    Thanks Phil, but one thing that was taken away from the original was the relative state of the Origin next to the "Sync" button. For example it used to show how many commits the local was ahead and/or behind. When can we get that back? The lack of it causes unnecessary clicks on Sync just to check.

  28. Avatar for Vince
    Vince February 26th, 2016

    I had to super-charge my own shell with a port of git-radar called git-psradar https://github.com/vincpa/g...

  29. Avatar for Rick Hodder
    Rick Hodder February 27th, 2016

    hi phil, thanks for this post. I'm using Windows 10, and when I put powershell into consolez's edit settings, and then run console, I get the message "Cannot load PSReadline module. Console is running without PSReadline", I've install-module PSReadline -force, but it doesn't fix the issue. do you know what I can do to get past this?

  30. Avatar for haacked
    haacked February 29th, 2016

    Hmm, based on this Connect issue, PSReadline is not available in an x86 console. https://connect.microsoft.c... I wonder if you can force an x64 console.

  31. Avatar for Rick Hodder
    Rick Hodder February 29th, 2016

    thanks, phil - I'll give it a shot!

  32. Avatar for nickwalt
    nickwalt April 12th, 2016

    Hi Phil, thanks for a great article.

    A few questions:
    1. If we want to use the latest Git version with Powershell ISE do we need to install Git for Windows?
    2. Is the intention there for GitHub Desktop to replace the Git for Windows installer and become the sole provider of a full Git experience in the command line?
    3. Is it possible to just have GitHub Desktop installed and configure Powershell ISE to execute all Git commands without needing to use the Git Shell shortcut? This could provide a seamless experience, aka bash.
    4. I want to keep my Git environment completely on cloud storage (OneDrive, etc), including GitHub Desktop (as well as Git for Windows) and all Git repositories. Is this possible? I'll also be configuring all Powershell modules and profiles to run from there, including all code editor configs.

    I'm running Windows 10 and pretty much use Powershell ISE exclusively (are DevOps interested in using the regular powersell.exe environment, much - really?).

    Cheers, nick.

  33. Avatar for haacked
    haacked April 12th, 2016

    > 1. If we want to use the latest Git version with Powershell ISE do we need to install Git for Windows?

    GitHub for Windows should work. If you need the absolute latest Git the day it comes out, then you can install Git for Windows.

    > 2. Is the intention there for GitHub Desktop to replace the Git for Windows installer and become the sole provider of a full Git experience in the command line?

    For those that like the experience we provide, yes because we automatically upgrade Git for you and provide a nice experience. Also keep in mind that we're packaging the same code as Git for Windows in a portable manner. So it's the same Git.

    > 3. Is it possible to just have GitHub Desktop installed and configure Powershell ISE to execute all Git commands without needing to use the Git Shell shortcut? This could provide a seamless experience, aka bash.

    Yeah. Just set up your PowerShell profile to load shell.ps1 per the instructions in this article.

    > 4. I want to keep my Git environment completely on cloud storage (OneDrive, etc), including GitHub Desktop (as well as Git for Windows) and all Git repositories. Is this possible? I'll also be configuring all Powershell modules and profiles to run from there, including all code editor configs.

    This is not a supported option at the moment. It might work if you map a drive letter to your OneDrive, but network issues using Git for Windows and GitHub Desktop against a "local drive" that is actually a flaky network could cause problems.

  34. Avatar for nickwalt
    nickwalt April 28th, 2016

    Thanks, Phil.

    For some reason, Disqus didn't notify me of your response and so I was looking at what others had done.

    I did find some good posts and the consensus was to use Git for Windows because it supported 64bit PowerShell and all Modules available in the ISE. See Mike Robbins' post about it:
    http://mikefrobbins.com/201...

    So, in answer to my questions 1 and 2 it seems that for those who wish to use PowerShell ISE with Modules the best method is to install both.

    However, it seems like the two environments are quite separate and that any authentication method established by GitHub Desktop is not used by Git for Windows.

    I guess that this was why I asked about intention to combine the two. A single installation that provided a full GitHub for Desktop and full Git for Windows experience would (obviously) be ideal. Especially, if that installer made it easy to manage Git setup across all of your PowerShell Hosts (powershell.exe, powershell_ise.exe).

    In a later update to the article, Mike also recommends using https:// instead of SSH, at least on Windows - which is also what GitHub recommends:
    https://help.github.com/art...

    Thanks for reminding me to RTFB regarding point 3. Actually, it makes sense now that I've been trying to figure out a way to make the PowerShell environment portable on OneDrive.

    Regarding point 4, I don't think OneDrive is susceptible to any network latency, because apps write to a local directory at full speed. OneDrive handles replication to the cloud behind the scene.

    Cheers. Thanks again, Phil.

  35. Avatar for haacked
    haacked April 28th, 2016

    > I guess that this was why I asked about intention to combine the two. A single installation that provided a full GitHub for Desktop and full Git for Windows experience would (obviously) be ideal.

    Ah, so there's some confusion here. We actually do provide the full "Git for Windows" experience, but we install it in a portable manner. The reason we do this is we support partial trust environments. So we lay down the same Git you get with Git for Windows, but we don't add it to the system path (as that would require elevation).

    The point of this blog post is to show how you can add the right paths to your PowerShell profile so that Git is available to every PowerShell session on your machine. Let me know if that addresses your issue or if I maybe misunderstood something.

  36. Avatar for William
    William July 9th, 2016

    Had the same problem. It seems like Posh-Git is only extracted / downloaded when you open PowerShell using the Git Shell shortcut (only once of course).

  37. Avatar for Rahul Soni
    Rahul Soni January 27th, 2017

    I have been using the new desktop client and it is serving the purpose quite well. Branching + Merging is not as intuitive and hence I am posting this for your readers https://www.attosol.com/cre...