{"id":1825,"date":"2012-11-27T18:00:01","date_gmt":"2012-11-27T16:00:01","guid":{"rendered":"http:\/\/planetozh.com\/blog\/?p=1825"},"modified":"2012-11-27T18:00:01","modified_gmt":"2012-11-27T16:00:01","slug":"efficient-git-setup-on-windows","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2012\/11\/efficient-git-setup-on-windows\/","title":{"rendered":"Efficient Git Setup on Windows"},"content":{"rendered":"<p>I think I&#39;ve set up a pretty efficient Git environment on Windows and, as promised in a previous post about my Git initiatic journey, I&#39;m sharing it, hoping it&#39;ll be useful to someone. Another quite lengthy post I&#39;m afraid, feel free to grab a cup of something before you start reading.<\/p>\n<p><!--more--><\/p>\n<h2>Foreword on client setup: GUI if you want, but command line anyway<\/h2>\n<p><strong><span style=\"text-decoration: underline;\">TL;DR<\/span>: GUI guy or not, you&#39;ll want to install a shell client.<\/strong><\/p>\n<p>Most guides about Git state that Git clients on Windows are less polished than SVN ones: I believe that&#39;s an outdated statement. If you&#39;re used to <a href=\"http:\/\/tortoisesvn.net\/\">TortoiseSVN<\/a>, you&#39;ll quickly feel home with <a href=\"http:\/\/code.google.com\/p\/tortoisegit\/\">TortoiseGit<\/a>.<\/p>\n<p>This said, I also believe that you should not overlook making yourself comfortable with the command line shell, for 2 reasons:<\/p>\n<ol>\n<li>First, Git is so vast that I doubt any GUI could include every possible command and option without making a nightmarish interface.<\/li>\n<li>Second and above all, every resources and tutorial you&#39;ll find will describe command line operations, so it&#39;s actually easier to learn how things work <em>in the console<\/em>, and eventually find what&#39;s feasible and easier with the GUI<\/li>\n<\/ol>\n<p>A quick personal note about the <a href=\"http:\/\/windows.github.com\/\">Github client<\/a>: I find it very limited. It&#39;s sexy, it&#39;s appealing, but its most useful feature is the &quot;Open command line shell here&quot; button. Do yourself a favor, save some time and skip it.<\/p>\n<h2>Installing msysgit then TortoiseGit<\/h2>\n<p><strong><span style=\"text-decoration: underline;\"><strong>TL;DR<\/strong><\/span>: Default options FTW, except &quot;Cheetah&quot;<\/strong><\/p>\n<p>First, you have to install <a href=\"http:\/\/msysgit.github.com\/\">Git for Windows<\/a>, <em>aka<\/em> <tt>msysgit<\/tt>. I don&#39;t have much to say here, just click &quot;Next&quot; when asked for some option, except on that one screen: when prompted for Windows Explorer integration, be sure to <strong>select and check<\/strong> &quot;Context menu entries&quot; and <strong>not<\/strong> the &quot;cheetah&quot; extension.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1844\" title=\"msysgit\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/msysgit1.png\" alt=\"\" width=\"515\" height=\"402\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/msysgit1.png 515w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/msysgit1-300x234.png 300w\" sizes=\"auto, (max-width: 515px) 100vw, 515px\" \/><\/p>\n<p>The reason is simple: those context menu entries are settings in the registry, and we&#39;ll hack and enhance them a lot later.<\/p>\n<p>Next, install <a href=\"http:\/\/code.google.com\/p\/tortoisegit\/\">TortoiseGit<\/a>, which is the GUI wrapper around Git. I don&#39;t remember doing anything that wasn&#39;t default during the setup so I won&#39;t elaborate further.<\/p>\n<p>In the rest of this guide I&#39;ll assume all install paths are default. You may have to adjust accordingly to your config, in particular regarding the location of the &quot;Program Files&quot; folder which differs from 32 to 64 bits setups.<\/p>\n<p>One thing to be aware of, if you are already a TortoiseSVN user: both &quot;Tortoise&quot; will share the same icon overlay. Unfortunately, it&#39;s impossible to visually differentiate the type of repository ; that would have been very neat but it&#39;s a Windows limitation and won&#39;t change soon.<\/p>\n<h2>Shell enhancement: Console2 to the rescue<\/h2>\n<p><strong><span style=\"text-decoration: underline;\">TL;DR<\/span>: cmd.exe sucks. But cmd + Console2 with tweaked settings rocks.<\/strong><\/p>\n<p>Think what you will about Microsoft, but there&#39;s one thing they&#39;ve mastered to an unmatched level: sticking with the same patheticly crappy command shell (aka <tt>cmd.exe<\/tt>) since 1914. Recentish versions of Windows ship with Powershell, but that&#39;s not better.<\/p>\n<p>Installing msysgit and the Windows port of many Linux utilies will provide several enhancements to the command line shell already (tab completion on commands, aliases for example) but we want more.<\/p>\n<p><a href=\"http:\/\/sourceforge.net\/projects\/console\/\">Console2<\/a> is shell wrapper (not a replacement to the good ol&#39; cmd.exe) that adds what&#39;s missing: mouse support to select, copy and paste, a tabbed interface, customizable shortcuts and more. You&#39;ll love it.<\/p>\n<p>Console2 is pretty cool but, probably because it didn&#39;t want to ashame cmd.exe too hard, it comes with really stupid default settings that need urgent tweaking. The following will make Console2 behave the same as your favorite Putty shell console:<\/p>\n<ul>\n<li>in the <strong>Appearance<\/strong> section, uncheck &quot;<tt>Snap to desktop edges<\/tt>&quot; (silliest setting *ever*)<\/li>\n<li><strong>Behavior<\/strong> section: check &quot;<tt>Copy on select<\/tt>&quot;<\/li>\n<li><strong>Hotkeys<\/strong>: I like to have <tt>Control T<\/tt> to create a new tab from the list we&#39;ll define later, and <tt>Ctrl + V<\/tt> for a keyboard paste.<\/li>\n<li><strong>Mouse<\/strong>: Assing <tt>Copy\/Clear<\/tt> and <tt>Select Text<\/tt> to <tt>Left<\/tt>, <tt>Paste text<\/tt> to <tt>Right<\/tt>, and maybe Menu to the Middle button<\/li>\n<li><strong>Tab<\/strong>: define a new tab and make it first in the list with the following settings:\n<ul>\n<li><strong>Title<\/strong>: <tt>Git<\/tt><\/li>\n<li><strong>Icon<\/strong>: <tt>C:\\Program Files (x86)\\Git\\etc\\git.ico<\/tt><\/li>\n<li><strong>Shell<\/strong>: <tt>\"C:\\Program Files (x86)\\Git\\bin\\sh.exe\" --login -i<\/tt> (mind the quotes)<\/li>\n<li>Startup Dir: D:\\home\\planetozh or what works for you<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1828\" title=\"console2\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/console2.png\" alt=\"\" width=\"553\" height=\"565\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/console2.png 553w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/console2-293x300.png 293w\" sizes=\"auto, (max-width: 553px) 100vw, 553px\" \/><\/p>\n<p>For the lazy here is my whole <a href=\"https:\/\/gist.github.com\/4067293\">console.xml<\/a> setting file (ie default settings plus tweaks described here). Drop this file in Console2&#39;s directory.<\/p>\n<p>The original Console2 project hasn&#39;t been updated for month, but the package you&#39;ll get from Sourceforge works fine on Win7. This said, I&#39;ve found that someone has forked the project and provides a <a href=\"https:\/\/github.com\/cbucher\/console\">newer version<\/a> with a few additions.<\/p>\n<h2>Regedit wizardry: ultimate context menus<\/h2>\n<p><strong><span style=\"text-decoration: underline;\">TL;DR<\/span>: a quick .reg hack will give lasers to your right click, pew pew<\/strong><\/p>\n<p>Now you have a fine tuned Console2, let&#39;s improve the right click context menus msysgit has installed. The default context menus pop up when you right click a folder icon and start Git&#39;s bash in <tt>cmd.exe<\/tt>, but with the help of Regedit we&#39;ll make that waaaaay better:<\/p>\n<ul>\n<li>context menus will also appear when you click inside a folder (in the white background, not on any icon)<\/li>\n<li>they will launch the improved Console2 shell instead of the cwappy cmd.exe<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/pewpew.png\" alt=\"\" title=\"pewpew\" width=\"349\" height=\"201\" class=\"aligncenter size-full wp-image-1848\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/pewpew.png 349w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/pewpew-300x172.png 300w\" sizes=\"auto, (max-width: 349px) 100vw, 349px\" \/><\/p>\n<p>First, dig in <tt>HKEY_CLASSES_ROOT\\Directory\\shell\\git_shell<\/tt>. The trick is to replace the default Git bash command with a shortcut to the Git tab in Console2: <tt>C:\\Program Files (x86)\\Console2\\Console.exe -t \"Git\" -d \"%1\"<\/tt><\/p>\n<p>The second trick is to create a Regedit entry to take care of your right-clicking in the background area of a folder: create a new key named git in <tt>HKEY_CLASSES_ROOT\\Directory\\Background\\shell<\/tt> with an empty string named <tt>NoWorkingDirectory<\/tt> and, in the Console2 command line, replace the directory argument <tt>%1<\/tt> with <tt>%V<\/tt> (go figure).<\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">Windows Registry Editor Version 5.00<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">[HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\git]<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">@=&quot;* Guit Bash&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&quot;NoWorkingDirectory&quot;=&quot;&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">[HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\git\\command]<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">@=&quot;C:\\\\Program Files (x86)\\\\Console2\\\\Console.exe -t \\&quot;Git\\&quot; -d \\&quot;%V\\&quot;&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">[HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\git_gui]<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&quot;NoWorkingDirectory&quot;=&quot;&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">@=&quot;* Git GUI&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">[HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\git_gui\\command]<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">@=&quot;\\&quot;C:\\\\Program Files (x86)\\\\Git\\\\bin\\\\wish.exe\\&quot; \\&quot;C:\\\\Program Files (x86)\\\\Git\\\\libexec\\\\git-core\\\\git-gui\\&quot; \\&quot;--working-dir\\&quot; \\&quot;%V\\&quot;&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">[HKEY_CLASSES_ROOT\\Directory\\shell\\git_gui]<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">@=&quot;* Git &amp;GUI Here&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">[HKEY_CLASSES_ROOT\\Directory\\shell\\git_gui\\command]<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">@=&quot;\\&quot;C:\\\\Program Files (x86)\\\\Git\\\\bin\\\\wish.exe\\&quot; \\&quot;C:\\\\Program Files (x86)\\\\Git\\\\libexec\\\\git-core\\\\git-gui\\&quot; \\&quot;--working-dir\\&quot; \\&quot;%1\\&quot;&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">[HKEY_CLASSES_ROOT\\Directory\\shell\\git_shell]<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">@=&quot;* Git Ba&amp;sh Here&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">[HKEY_CLASSES_ROOT\\Directory\\shell\\git_shell\\command]<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">@=&quot;C:\\\\Program Files (x86)\\\\Console2\\\\Console.exe -t \\&quot;Git\\&quot; -d \\&quot;%1\\&quot;&quot;<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Copy that into a raw text file named <tt>blah.reg<\/tt> on your desktop, edit if needed (make sure the paths match, mine here are defaults (keep the double backslash mayhem intact)) and execute the reg file to merge into your registry.<\/p>\n<h2>Spicing it all: .bash_profile hints<\/h2>\n<p><strong><span style=\"text-decoration: underline;\">TL;DR<\/span>: smart prompt and dynamic MOTD for the win.<\/strong><\/p>\n<p>You&#39;re almost there! Now that you have a cool shell that&#39;ll work just the same way as when you&#39;re using Putty or a Unix shell, let&#39;s leverage what bash has to offer.<\/p>\n<p>First, a <strong>nicer and smarter prompt<\/strong>. Mine shows current path and current branch if applicable. Also, since I don&#39;t work in what Windows considers my home directory (ie <tt>C:\\Users\\Ozh<\/tt>) but in <tt>D:\\home\\planetozh<\/tt>, the <tt>$(pwd | sed)<\/tt> trick here shortens the displayed path to saves a few chars.<\/p>\n<div id=\"ig-sh-2\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">PS1='\\[\\033[32m$(pwd | sed -e 's!\/d\/home!-!')\\033[36m $(__git_ps1 &quot;%s&quot;)\\033[0m\\]<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">$ '<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Add this to <tt>C:\\Users\\Bobby\\.bash_profile<\/tt> (hint: <a href=\"https:\/\/gist.github.com\/4131243\">how to create dot files<\/a> in Windows if you&#39;re having trouble with this)<\/p>\n<p>Next, a <strong>useful dynamic MOTD<\/strong>.<\/p>\n<p>When you launch a new shell, you&#39;re shown the content of the default MOTD (located in <tt>C:\\Program Files\\Git\\etc\\motd<\/tt>) which just contains a completely useless reminder about <tt>git --help<\/tt>.<\/p>\n<p>Upon launch, my shell checks if we&#39;re in a git project (ie if <tt>git rev-parse --git-dir<\/tt> triggers an error or returns something) and, if so, calls <tt>git branch<\/tt> to list existing branches and <tt>git status<\/tt>, which is a really handy command that suggests hints on what to do next as well as a few quick sanity checks and reminders (untracked files you&#39;ve forgotten to git add for instance)<\/p>\n<p>Add the following code to your <tt>.bash_profile<\/tt>:<\/p>\n<div id=\"ig-sh-3\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">if [[ $(git rev-parse --git-dir 2&gt; \/dev\/null) &amp;&amp; -z &quot;$GIT_MOTD&quot; ]]; then<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; echo -e &quot;\\e[00;32m- \\e[01;33mWelcome $(id -u -n)&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; echo -e &quot;\\e[00;32m- \\e[01;32mGIT BRANCH \\e[00;32m-----------------------------------------------------\\e[00m&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; git branch<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; echo -e &quot;\\e[00;32m- \\e[01;32mGIT STATUS \\e[00;32m-----------------------------------------------------\\e[00m&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; git status<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; echo -e &quot;\\e[00;32m------------------------------------------------------------------\\e[00m&quot;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; GIT_MOTD=1;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">fi<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Screenshot of smart prompt and dynamic MOTD, pew pew :<\/p>\n<p><a href=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/motd.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/motd.png\" alt=\"\" title=\"motd\" width=\"693\" height=\"341\" class=\"aligncenter size-full wp-image-1846\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/motd.png 693w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/motd-300x147.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/a><\/p>\n<h2>Bonus trick 1 : get rid of vi<\/h2>\n<p><strong><span style=\"text-decoration: underline;\">TL;DR<\/span>: not a Linux bearded geek, right? Hate <tt>vi<\/tt>, right?<\/strong><\/p>\n<p>I&#39;m going to lose a lot of internet geek points here but I&#39;ll say it anyway: I&#39;ve always considered Vi (or Vim), which is the default editor on many setups, as the most efficient user repellent ever. Whenever I log on a new shell, the first thing I check is if <tt>nano<\/tt> or <tt>pico<\/tt> are available (for the clueless: intuitive and simple text editors where you don&#39;t need insane key combo such as <tt>!:qomg<\/tt> to execute a simple command). The default console text editor in msysgit is, guess what, vi, so we&#39;ll simplify things ASAP.<\/p>\n<p>First, download <a href=\"http:\/\/www.nano-editor.org\/download.php\">Nano<\/a>, yes there are Windows ports, and drop the files in <tt>C:\\Program Files\\Git\\bin<\/tt>. Next, launch your shiny Git console and type the following:<\/p>\n<div id=\"ig-sh-4\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">git config --global core.editor nano.exe<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Now, interactive commands such as <tt>git commit<\/tt> will send you into <tt>nano<\/tt>. I thought it made sense to keep things in the console when you work from the console, but if you want to open your regular text editor instead, say, Notepad++, that&#39;s not a problem:<\/p>\n<div id=\"ig-sh-5\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">git config --global core.editor &quot;'C:\/Program Files\/Notepad++\/notepad++.exe' -multiInst -notabbar -nosession -noPlugin&quot;<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<h2>Bonus trick 2 : make TortoiseGit remember your passwords<\/h2>\n<p><strong><span style=\"text-decoration: underline;\">TL;DR<\/span>: C:\\Users\\Bob\\_netrc<\/strong><\/p>\n<p>By default TortoiseGit doesn&#39;t store any password, as TortoiseSVN does (or I&#39;m too dumb to find where this is stored). There are two ways to circumvent this.<\/p>\n<p><strong>First option<\/strong>: you can generate SSH keys (on <a href=\"https:\/\/help.github.com\/articles\/generating-ssh-keys\">Github<\/a> for instance) and save them in Tortoise, but I&#39;ve <a href=\"http:\/\/planetozh.com\/blog\/2012\/11\/so-ive-tried-git-and-its\/?cp=1#comment-198554\">heard<\/a> that it&#39;s not obviously obvious.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" title=\"sshkeys\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/sshkeys.png\" alt=\"\" \/><\/p>\n<p>I don&#39;t know what loops Otto had to go through, but in case you want to investigate that solution, <a href=\"http:\/\/stackoverflow.com\/a\/4356869\/36850\">this post on SO<\/a> has what seems like good pointers.<\/p>\n<p><strong>Second option<\/strong>, what I&#39;ve done: simply save your login and password in a file named <tt>_netrc<\/tt> that you&#39;ll create in your User directory (eg <tt>%USERPROFILE%<\/tt> eg <tt>C:\\Users\\Bob<\/tt>).<\/p>\n<p>The syntax is simply: <tt>machine blah.com login bob password zomgp4ssw0rd<\/tt> with one line per machine<\/p>\n<p>If you frequently work with multiple repositories and different logins, here is a simple <tt>.bat<\/tt> file that prompts you for the needed info (host, login, password) and stores everything in the adequate file.<\/p>\n<div id=\"ig-sh-6\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">@echo off<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">SET \/P HOST=What is the hostname i.e github.com?<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">SET \/P USERNAME=What is your username?<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">SET \/P PASSWORD=What is your password?<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">echo machine %HOST% login %USERNAME% password %PASSWORD% &amp;gt; &quot;%USERPROFILE%\\_netrc&quot;<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Paste that into <tt>gitpass.bat<\/tt> in your htdocs root and just run it everytime you need to store a new login\/password pair.<\/p>\n<h2>Further improvements<\/h2>\n<p><strong><span style=\"text-decoration: underline;\">TL;DR<\/span>: fine, don&#39;t read! I won&#39;t make it any longer!<\/strong><\/p>\n<p>You&#39;ll probably want to dwelve in crafting your own Git aliases for enhanced command line productivity. There are plenty of tutorials on this everywhere and I&#39;m not personally a fervent user of aliases, which I find to be quite blockers once you find yourself on another computer or shell that does not have them. The only one I have right now, and don&#39;t use except to show off when my wife enters the vicinity is:<\/p>\n<div id=\"ig-sh-7\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">alias glog=&quot;git log --graph --pretty=format:'%Cred%h%Creset %C(cyan)%an%Creset -%C(blue)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative&quot;<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>The next thing I want to play with is git hooks, which are simple text files (hint: everything in Git is simple text files, seriously, SVN, steal that please) to perform more or less complex automated tasks, such as having a <a href=\"https:\/\/gist.github.com\/4154909\">branch sync with another one<\/a>. I&#39;m sure there are lots of crazy fun stuff to do with hooks :)<\/p>\n<p>If you have any other improvement that makes Git any easier or faster, be sure to share!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I think I&#39;ve set up a pretty efficient Git environment on Windows and, as promised in a previous post about my Git initiatic journey, I&#39;m sharing it, hoping it&#39;ll be useful to someone. Another quite lengthy post I&#39;m afraid, feel free to grab a cup of something before you start reading.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[396,395,4],"class_list":["post-1825","post","type-post","status-publish","format-standard","hentry","category-published","tag-git","tag-tricks","tag-windows"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/1825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/comments?post=1825"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/1825\/revisions"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=1825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=1825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=1825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}