Using Git on Windows
- Mar 24, 2019
Using Git on Windows is way easier once you find a combination of tools that you’re comfortable with.
In this blog post you’ll learn about:
- Using Git via the command line on Windows
- A great Git GUI client for Windows and Mac
- The tool that I use for diffs, and resolving any Git merge conflict that may occur (including 3-way merges)
- Using Git with SSH authentication on Windows via .bashrc and Bash shell
- My .gitconfig
Using Git on the command line
I use Git For Windows via the Bash shell which comes bundled with Cmder, and always have a console window open.
Prior to switching to mostly Windows development back in 2006, I used Linux nearly exclusively, and still find the Bash shell to be a more comfortable interface than the regular Windows command prompt.
Git commands for Windows are the same as they are on Linux.
I find the command line generally easiest for for creating commits, rebasing, pushing branches, etc.
Here’s what the Cmder console looks like when you’re using Bash:
Make sure that you download the full Cmder, which contains Git for Windows, along with many of the tools that you may be already familiar with such as grep and SSH.
When you first open Cmder, the default shell that pops up will be the regular windows CMD shell, wrapped within the Cmder console.
Because the CMD shell is wrapped in Cmder, the interface is a big step up from the regular built-in CMD shell that comes with Windows. You get all the things that you’d expect from a modern console.
To open the Bash shell within Cmder, start by clicking the green plus icon in the lower right of the window, then:
Using Sourcetree as a Git GUI Client
I use Sourcetree for anything that feels more convenient via a GUI such as browsing the source history, or when I want to add or discard specific sections of specific files to a commit.
Sourcetree is available for Mac and Windows, and I find it way easier to use than that default gitk and git-gui.
Before using SourceTree, I used to use Tortoise Git, which is still around if you want to check it out.
Diffs and 3-way merges via Sourcetree and Beyond Compare
Whenever I need to see diffs, or resolve a merge conflict, rather than continuing on the command line, I switch to Sourcetree, and use it to open Beyond Compare, which is my favorite tool for diffs and 3-way merges.
I’ve been using Beyond Compare Pro for years, since first reading about it on Nick Craver’s Blog. Before Beyond Compare, I was using Winmerge, which is a great alternative.
I can’t quite remember why I switched from WinMerge to Beyond Compare, but both tools are worth checking out to see what you prefer.
Aside from Beyond Compare being great software, one of the things that has kept me using it has been the fact that they have consistently offered free upgrades to the latest version of their product - rather than paying for a new license every year or two, I’m still using my original license which I purchased about 6 years ago.
An example diff in Beyond compare
An example 3-way merge in Beyond compare
Editing Git commit messages
I use Notepad++ for editing commit messages, and for interactive rebase:
Using SSH to access Git repos
I use SSH to manage access to my Git repos, and have .bashrc set up to automatically add any ssh keys on startup.
Here’s the contents of my .bashrc file, which sets up ssh with my Github SSH key:
eval $(ssh-agent)
ssh-add ~/.ssh/github
Here’s how to set up SSH keys for Bitbucket, and how to set up SSH keys for Github
My .gitconfig
Here’s my .gitconfig file which ties everything together, using notepad++ for editing commits, setting up interactive rebases, etc, and Beyond Compare for diffs and merges.
[user]
name = Matt
email = [email protected]
[core]
autocrlf = true
editor = 'c:/program files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin
[difftool "sourcetree"]
cmd = 'C:/Program Files/Beyond Compare 4/BComp.exe' \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
cmd = 'C:/Program Files/Beyond Compare 4/BComp.exe' \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
trustExitCode = true
Thanks for reading!
I hope this post was helpful. What tools do you use? Any feedback? Is there anything that I haven’t covered that you’d like to more about? Let me know in the comments below