This guide will get you through installing Git on Microsoft Windows.
If you are accustomed to using Microsoft Windows to do all your software development and would like to use a version control system (VCS) like Git, you have some challenges ahead of you. To use Git and learn it right you have start at the low level to know whats available and use it in its native tongue. If you never used Linux before and are not accustomed to doing things at the command line, that will be your first hurdle. The second, learning Git itself.
So what is Git for Windows? It is a software distribution that contains Linux like tools to do version control of your programming assets. Version control allows you to store and recall versions of a file over time. Typically, this is used for source code to track a history of changes. But it doesn’t have to be. It can be any file type like a PDF, an image, even video.
Git is a distributed VCS with server side software typically run on Linux systems and client software run on Linux desktops. Distributed Git mirrors the version control database across servers and clients. This is to avoid the problem in the older approach of VCS, where only one centralized server existed. If that server went down, all the other clients would not be able to access it.
This distribution, Git for Windows, is client software meant for running on Microsoft Windows boxes. You are probably wondering “But how does Linux run on Windows?” It doesn’t. The software that Git for Windows uses simulates the Linux environment. Tools like these have been around for a while. Cygwin is the more common environment available and there are many forks off it like MSys and MSys2.
Walkthrough: Installing Git for Windows
Ok lets get started.
The Git client is available for many different O/S platforms including Mac OSX, Solaris, Linux, and Windows. We’ll focus entirely on Microsoft Windows here. With the Windows release, there are 32 bit, 64 bit and portable versions available. Download Git for Windows and choose the appropriate version. I will be assuming you are downloading the 64-bit Windows version as I will be using that. The file is about 32MB in size and should take less than a minute to download. After completion, run it.
First thing that will come up is a GNU Public License. Git for Windows is Open Source and by you using the software you agree to abide by this license.
The Select Component screen appears and you see a hierarchical tree full of stuff you can choose from. Go click on every checkbox. All of it is harmless when enabled and are for your own benefit to integrate the software into your native O/S. Things like file association, icons and Windows Explorer context menus. It will take up about 190MB of disk space.
Here’s a tip. Do yourself a favor and install Git in Drive:\Git, not in C:\Program Files\Git or anything 2-3 levels deep. Why? Because you \dont\want\to\have\to\do\this when changing directories all the time at the command line.
When it comes to adjusting the PATH, these options are totally confusing. The installer assumes you know what the heck the Git for Windows tool is, what it means to run Git from the Windows Command Prompt, running Git (which one?) and the Unix tools that are available.
Having used Linux, version control systems and other development tools over my professional career, I have a sense of what all of this is. But given these explanations to install, I have no freaking clue. So lets be a little daring. If you are like me and see “Use Git and optional Unix tools from the Windows Command prompt” and know a little Linux Bash, go for it. If you don’t, go for it anyway. You are going to have to learn a new skill. Given that Unix tools are going to be installed you have ask, “Which one?” Cygwin? Cash? Msys? No idea. You would think they would give you more information.
Then there’s that red warning label that sticks out like a sore thumb. What it means is, if you use this option you can potentially hose your existing system with the Unix tools taking over. So we need to be a little careful here and remember this.
Now we come to choosing a SSH executable. For most Microsoft Windows users and developers, SSH isn’t going to be something one is familiar with. Fortunately, I dabble in Ubuntu and written some articles on SSH in the past so I know a little to be dangerous. SSH is almost a given in the Linux world. You have to know what it is and how to use it. For now, lets just choose OpenSSH and forget about Tortoise Plink (WTF is that anyway?).
Configuring the line ending conversions. Ok, this brings up ugly memories. I been bit in the ass with this kind of thing before and it was hell to figure out what the problem was. What this is about is that on Windows, a line is ended with a carriage return and line feed (CRLF). Under Linux, it just uses a line feed (LF). As you can imagine, this can be a problem, especially when you bring a text file up in your text editor.
In the Distributed CVS model, the version control database is stored on servers and clients. As files are transferred and stored across a non-specific O/S platform, something must be set to let both the server and client know if CRLF or LF is being used. So this question is all about how your client is going to store them on your Windows box and communicate this when its role is as a repository`.
Of the three options, the Checkout as-is, commit as-is is just plain dangerous. I hesitate to say, “WTF. Why even include it in the installation in the first place!” So what’s left? Either Windows or Unix translation. Lets choose “Checkout Windows-style, commit Unix-style line endings” since that seems reasonable. What this means is that everytime you store your files, they will only have a line feed in it as it will be stored Linux style. But when you check out the files from the database repository, they will have CRLF in them.
Now we come to setting the terminal emulator. I chose Use MinTTY and not CMD.EXE. MinTTY is the Cygwin terminal emulator for Cygwin, and MSys. It is Xterm compatible, which means it emulates the Unix X Window System. Xterm is a text oriented user interface, unlike a terminal window that runs within a GUI. It emulates a host system, just as if you were physically there typing things in, on your client terminal. Xterm in turn runs the Bash shell which is an interpreter than understands Bash language commands. Again, distance yourself from MS Windows and use Linux tools to educate yourself.
For configuration of extra options, select the Enable file system caching and Enable Git Credential Manager. You’d want to do this to increase file read/write performance and to make authentication between you and the Git Server seamless. In many operations that you perform in your Git terminal, a username and password is required. You don’t want to have to do this for every operation. So what happens is that these credentials are stored just once and then you are not annoyed everytime for operations thereafter.
After a few minutes, Git will be installed. Go run Git Bash by clicking on the desktop icon. What you should see is MinGW64 running a Bash terminal window. MinGW64 is pretty much a development environment that runs GNU development tools (GCC) under a Win32 API. GNU Compiler Tools (GCC) consists of many compilers including C/C++, Object C/C++, Fortran, Go, Java, and creates target executables for many processors including Intel, MIPS, SPARC, and ARM.
Lets do our first Bash command! Try looking at the current directory using the ls list command:
Try these other commands too to prove to yourself your MSys Linux-like environment is setup properly:
env Shows environment cd /bin Change directory to /bin ls -al List directory clear Clear terminal screen free Show memory usage (not supported) cal Show calendar (not supported) pwd Show current working directory whoami Show who the current user is who Show all users using the system (does't work) top Show running processes (not supported)
Be aware that some things are not supported. Its not a full fledged Linux environment but rather just enough to make it usable.
GUI Git Clients for Windows
If all of this seems overwhelming, there is another way. Whenever you have to start learning everything from a command line, there is an investment in time that is needed. As mentioned earlier, you should learn Git from the Bash terminal. But if you don’t wish to go that route, here are some GUI Git clients that you can use instead:
- SmartGit ($6.99/month or $99+; Windows/Mac/Linux)
- GitHub Desktop (free/ Windows/Mac)
- SourceTree (free; Windows/Mac)
- Git Tower ($79; Mac/Windows)
Of these, its best to use a cross platform solution so that the time you spent learning the software on Windows will be useful for running the same software on Linux or Mac.
Up to this point, we have managed to install the Git for Windows distribution on your Windows system. You learned the steps along the way and what each step meant. We looked at the components and what was involved at a lower level.
We also know about several GUI Git clients that you can use if you do not want to use the command line.