4 min read

Setting Up Git on Windows

These days, Git is the default way to perform version control when developing code. I could go on a prolonged rant about how economists (and most social scientists, in my opinion) should invest a week of their time to learn how to stop worrying and love the tool. However, such rants can be easily found on Google, and, instead, I decided to draft up a quick guide on how to get Git up and running on a Windows machine. Git usually comes pre-installed on a Mac or Linux machine already, but the later part of the guide would be helpful for those platforms as well.

You will first need to obtain Git, I suggest getting the installer from git-scm.com. It is a pretty standard Windows-style installer, and I strongly encourage you to accept the default options: first, use Git only inside Git Bash, and second, checkout Windows-style, commit Unix-style. I personally tend to override the default editor choice from vim to nano, but this is more of a style preference. Other choices are less relevant.

Once the installation concludes, you can start Git Bash, and it will open up a terminal window with a standard Unix-style bash shell, which will be Git-aware. By default, the only editor it will support will be vim, which is powerful but has a steep learning curve. For new users I suggest using nano, which is basically a Linux version of Notepad. Test if you’ve installed nano typing nano inside Git Bash shell - if successful, press Ctrl+X to exit back to shell.

You are now all set to use Git locally, provided that you know how to do it. To harness Git’s full power, however, you will want to be able to interact with a remote repository. The two best web services to host a remote Git repository are GitHub and Bitbucket. GitHub offers free repositories with unlimited number of users, provided that you make all the code publicly accessible to everyone via their web interface. Until recently you had to pay GitHub to make your code private, but this is no longer the case as of this post. Bitbucket instead offers private repositories, but limits the number of users on them to five, and asks you to pay them if you need more users. The choice is yours to make, I use both for different applications.

To streamline Git operations I will talk about setting up an SSH identity. Strictly speaking, you don’t really need this to use Git with eithe GitHub or Bitbucket – you could push and pull over HTTPS instead of SSH by typing the password from your corresponding account every time. However, if your password is sufficiently long and secure (and it should be), this can get pretty tedious fairly quickly. That is where an SSH identity will come handy: it will teach GitHub and Bitbucket to recognize your computer when you try accessing a Git repository from it. The downsides are twofold: first, anyone with access to your computer will be able to interface with GitHub and Bitbucket repositories; second, if you routinely work on a number of computers you would need to go through this process on each of them.

Bitbucket has a comprehensive guide on setting up SSH identity, which I suggest you follow from start to finish. Once this is done, you should be interact with Bitbucket from Git Bash without any issues. To do the same with GitHub, you can use the same SSH identity. Simply use Notepad to open the file id_rsa.pub that you created previously, copy its contents, and use the guidance in the “Adding a new SSH key to your GitHub account” part of this guide to add the key to your account. This should be sufficient.

Congratulations, now you can freely use Git on Windows and interact with two major Git hosting services without any hassle! There is nothing really difficult about this process, but putting it all together can be less than straightforward for a beginner, and hopefully this guide will make it easier.