Setting Up Git and Working with GitHub in Windows

Like most of the web industry, I use Git for version control, and so far I’ve mainly worked with GitHub remotes, so that’s what I’m set up for now. This post will cover how I install and configure Git to work smoothly in Windows.

Disclaimer: I don’t do much web development in Windows these days, and most of this was written a couple of years ago with a few recent edits to bring things up to date. I did run through these steps again as I just reinstalled Windows 10 and needed to get this all set up for the rare occasion I need to work on a project in Windows.

I’ve tried GitHub Desktop, GitKraken, SourceTree, and other programs that “include” Git automatically, but ultimately I prefer to have Git for Windows installed first so that I’m not totally dependent on a particular company’s implementation or “flavor” of Git. It seems “closer to the metal” for me and doesn’t preclude using any of those tools also, so why not? I also prefer using Git Bash that comes with it for command line work instead of the Windows default command line or PowerShell. I believe it’s worth learning to use Git via the command line because

  1. there are some commands a GUI may not be able to perform,
  2. you may end up in a situation where you don’t have access to a Git GUI for some reason so you should be familiar with the command line, and
  3. many tutorials that involve issuing git commands do so using the command line because the commands are the same on all platforms; different GUIs have different ways of creating a branch, for example, while with a command line it’s always git branch name-of-branch if you are on Windows, OS X, or Linux.

Install Git for Windows

First, install Git for Windows from https://git-scm.com/download/win. The download should start automatically. Run the installer and choose the options you want. I use mostly the default installation options and they have worked just fine for me. You may want to adjust settings for your particular workflow or preference.

Once the installation is complete, close the installer and go to Start menu > Git > Git Bash to start the git-bash command line and run git --version to confirm that Git is installed correctly. It should display the version.

Git version displayed in Git Bash
Git version displayed in Git Bash

Configure Name and Email for Commits

Now that Git is installed, I recommend setting up a global git config, including your email and name to be associated with commits. Multi-user configs are possible (e.g. having a work name/email for work projects and a personal name/email for personal projects), but outside the scope of this post. To get started, type these commands in Git Bash:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

This information will be stored in a .gitconfig file located at your HOMEDRIVE HOMEPATH which is typically C:\Users\Yourusername\ in Windows 10. You can edit this file in a text editor in the future rather than use git commands via the command line.

Note: If you install a Git GUI, it may also ask for your name and email to associate with commits. Be sure to use the same name and email that you used in the command line so you can commit from the command line or the GUI with a consistent user.

How to Avoid Entering GitHub Credentials Repeatedly

Now you can commit changes locally and they will be associated with your email and name. So far so good, but if you were to try to push commits to a remote GitHub repo or clone a private GitHub repo, you would be prompted to enter your GitHub username and password. This can get pretty tedious to do over and over, so for convenience I recommend storing your GitHub credentials using Windows Credential Manager or setting up an SSH key. Member when we installed Git for Windows and enabled Git Credential Manager? Oooh I member! This will allow you to save your credentials.

Using Windows Credential Manager

Saving your credentials in Windows Credential Manager is simpler than using an SSH key but potentially less secure. To use this method, start by typing this command in Git Bash:

git config --global credential.helper wincred

This updates the global .gitconfig file and tells Git that you want to use wincred to store your credentials. Now the first time you try to push to a remote GitHub repo, you’ll be prompted for your GitHub username and password. After that you won’t be prompted for future interactions with your remote because your username and password will be stored. I assume this works for other Git remotes like BitBucket, etc.

You must provide credentials for GitHub until they are saved.
You must provide credentials for GitHub until they are saved.

You can verify that your credentials are stored by going to Control Panel > User Accounts > Manage your crednentials. You’ll see the entry(ies) for github.com listed.

GitHub credentials are stored in Credential Manager.
GitHub credentials are stored in Credential Manager.

That’s it! No more entering your username and password for GitHub.

Using an SSH Key

Setting up an SSH key is more secure than using Windows Credential Manager, but it also requires more steps. GitHub has a several help articles on this that cover the topic thoroughly, so I won’t repeat the process here.

Thoughts on GUIs for Git

I grew up using PCs, and except for a few years in the MS-DOS days I’ve been used to GUIs and not the command line. When I started using OS X a few years ago for web development I became much more familiar with the command line. But I appreciate a well-designed interface and I know many other Windows users prefer a GUI, so I’ll lay out my thoughts on the ones I’ve used.

Git GUI  (from Git for Windows)

I haven’t really used this other than to see what it looks like. It seems to be a serviceable GUI for viewing changes and committing them. The interface is pretty basic and visualizing the history of the repo requires a few extra clicks, but it should work fine for typical Git tasks like branching, commiting, and pushing.

GitHub Desktop

This was my first experience with Git and with GitHub. When opening very large repos it seemed to slow down, but otherwise I found it easy to switch between branches, see what files/lines I’d changed, make commits, and push them up to GitHub. It was easy enough to find my way around and handle basic Git tasks. I haven’t tried it in years, so it may be quite a bit different now.

GitKraken

After my initial experience with GitHub Desktop I stuck to the command line only for a long time. When I heard about GitKraken I decided to try it out. I have to say, this is my favorite Git GUI so far. It integrates easily with GitHub, has a beautiful and intuitive design, and makes visualizing branches very easy. I ran into some issues early on with it freezing or crashing, but recent versions have been very stable for me. Also take note that it is free for personal use, but requires a paid license for commercial use. I use this as my primary Git GUI nowadays.

SourceTree

I used SourceTree as my primary Git GUI up until about a year ago, and I can see why many people like it. It’s fully-featured, works in Windows and macOS, and complements Git for Windows nicely. There are a ton of options that I never had time to mess with but looked very useful. One thing that bothered me was the lack of a “dark” theme for the UI. I prefer to use a dark theme when possible, so this was a minor bother for me.