Nithin Bekal

Posts About Notes Slides

Set up Git on Windows

31 Aug 2010

In this post, I will describe the steps to install git on a windows machine, create a local repository, and then push that repo to your github account. This is a beginner level tutorial for those using windows, but except for the part about installation, it is common for all OSes.

Installation and set up

Download and install msysgit from http://msysgit.github.io/. Msysgit comes with a GUI tool and a command line version.

Next you have to set up your name and email into git configuration. For this, open git bash and use the following commands:

$ git config --global user.name "Nithin Bekal"
$ git config --global user.email me@myemail.com

Creating the first repo

Now that the installation and configuration steps are done, let’s create our first repository. Create a folder called my_project and add some files to it. I created a rails project using rails my_poject since that automatically generates many files and folders.

Go to the project directory

$ cd my_project

Initialize a git repository for the project:

$ git init

Add all the files in the project to the repository:

$ git add .

Make the first commit.

git commit -m "First commit."

This commits all the changes (all the files in this case, because we have a new repo here) to the repository along with the message “First commit”.

Pushing the repo to Github

The next step is to push this repository to Github. First of all, you need to sign up for an account (if you don’t already have one) on Github. Once you’ve created the account, create a new repository called my_project.

Before you can start pushing to Github, you need to create an ssh key for your computer and copy the public key to your Github account.

Create SSH key:

$ cd ~
$ mkdir .ssh
$ cd .ssh
$ ssh-keygen -t rsa -C "you@yourmail.com"

Now in giithub, go to Account settings > Add SSH keys > Add another public key and copy the contents of the id_rsa.pub file there. You will have to create an ssh key and add it to github for each computer from which you want to push repos to github.

To push the local repository to github:

$ git remote add origin git@github.com:my_username/my_project.git
$git push origin master

Now if you open the page for the repository on your browser, you can see the files of your project visible there. If you have a readme file in your project folder, the contents of that file will also be displayed. That’s it! Now you have the git repository available on Github.

Hi, I’m Nithin Bekal. I work at Shopify in Ottawa, Canada. Previously, co-founder of CrowdStudio.in and WowMakers. Ruby is my preferred programming language, and the topic of most of my articles here, but I'm also a big fan of Elixir. Tweet to me at @nithinbekal.