Git on Windows for Newbs

Git on Windows for Newbs

Tutorial Details
    • Difficulty: Easy
    • Estimated Completion Time: 10-15 Minutes

Git has come a long way since its introduction, and has become significantly easier to work with in a Windows environment. In this tutorial, we are going to get setup with Git on Windows.

This article was written with the GUI in mind. I will NOT go over the command line usage, because there are many resources that already teach that aspect of Git. I made this for the true Windows users, the GUI ninjas. If you are like me and prefer a GUI over the command line, then this is the tutorial for you!


Step 1: Install Git

The first thing we need to do is install Git on Windows; you can do so with the following steps:

  1. Download and install the latest version of Git for Windows
  2. Use the default options for each step in the installation
  3. Remove Git Bash Desktop Icon
  4. Go to Start > All Programs > Git > Git GUI and make a Desktop Shortcut

Strangely, the last step seemed a bit confusing if you don’t have Windows Search enabled. You can also pin Git GUI to the taskbar and/or the Start Menu.

It is important that you use all the default settings because they are supported by all major repository vendors such as Github, Bitbucket, and Beanstalk.


Step 2: Setup SSH Keys

Compared to Git Bash, setting up a SSH Key for your computer is relatively easy. Simply open Git GUI.

Git Gui

Now click on Show SSH Key under the Help Menu.

Git Gui SSH Key

It’s possible that there is already a SSH key on your system; it’s best to remove or backup the key if you do not know where it came from. To do so, simply remove all files within: C:\Users\<username>\.ssh. Be sure to replace <username> with your Windows username.

You can generate a SSH key by clicking on the Generate Key button. When you do so, you will need to supply a passphrase for security purposes. Remember this passphrase; you will need to use it later.

Setup SSH Key with Hosted Git Repository

Github is not the only hosted Git repository available. It is, however, the most popular solution, and we’ll use it as an example.

The SSH key you created allows you to push your changes to a hosted repository. So, in order to push changes from your computer, Github needs to know your public SSH key. That is easily accessible; simply click the "Copy to Clipboard" button.

Next, you need to provide your hosted repo service with your public SSH key. Similar to Github, most of these sites usually have a tab, called "SSH Keys". Click the tab and add your SSH key to the website.

Git Gui Stage

The Title field is just a label to identify the SSH key; it is for your purposes only. For example, "WindowsPc", "Macbook", "Linux". Just make sure it accurately describes what device the SSH key is assigned to.


Step 3: Getting Started with Git

Next, we need a Git repository, and we’ll create a new remote repository on Github.

Create a Remote Repository

When creating a remote repo, Github offers to initialize the repository for you. This is a nice option, but for the purpose of learning how to setup for alternative websites, we will not check the initialize box.

Github Create Repository

Create a Local Repository

Now, we’ll create a local repository. In our Git GUI, click on "Create New Repository".

Git Gui

Select the location you wish to store your repository in. It is important to note that the selected repository location MUST NOT exist. So select the location you wish, and append the name of the folder you want the repository to be in, like this:

Git Gui New Repository

In order for this new repository to be initialized, you must first create a file, any file, in your local repo. Then, you must Commit and Push to the remote Git repository location. We’ll review committing and pushing in Step 4; I recommend you skip ahead if you do not wish to clone a repository. Your remote Git location should look like similar to this: git@github.com:Username/repository-name.git.

Clone a Remote Repository to a Local Repository

As I noted before, Github can provide you with an already initialized repository, and you can get started a lot faster than you normally would. In order to clone a repository, click on the "Clone Existing Repository" link in the Git GUI window. An existing repository is one that is already initialized and/or has commits pushed to it.

In the Source Location field, fill in the Git remote repository location. The Target Directory field works much like how I showed you how to create a repository earlier. Short version: select the location and append the folder you want the files to be in. Git will attempt to create it, and it will fail if it already exists.

Git Gui Clone Repository

There you go; now you should be all set to work locally.


Step 4: Working with the GUI Client

The Git GUI makes it easier to perform Git-related tasks, such as staging changes, commits, and pushes.

Stage Changed

When you move files to a Git directory, you will see all the files in the "Unstaged Changes" window. This basically means that new files have been added, removed, updated, etc. You can click on the "Rescan" button in order to see any new changes that may have occurred.

Git Gui Stage

When you click the "Stage Changed" button, it will attempt to add all the new files to the Git index.

Git Gui Stage

Commits:

After you’ve staged your changes, you then need to commit them to your local repository. Type a Commit Message that makes sense to the changes that were made. When you are done, press the Commit button.

Git Gui Commit

Pushing

Before others can access our new code, we need to push these changes to our hosted repository. Without pushing the changes, others would not be able to access the code.

Before we can proceed to push, we need set up a location to push to. Most folks refer to this location as "origin". If you wish, you can select an option in the "Further Actions" area, but in my experience, doing nothing will benefit you the most. You can always clone or push later.

Git Gui Remote Add Origin

After adding the remote origin, you can simply press the Push button. It will ask you where you want to push to; most likely "origin" will be pre-selected (and it may be your only option). So simply click on the Push button again.

Git Gui Push

Next, you will be bombarded with window after window. But don’t worry, this only happens the first time. Simply follow the instructions given to you.

Git Gui Push

Git will ask you the passphrase of your SSH Key.

Git Gui Stage

Don’t panic if you see more then one request of your passphrase. It is completely normal! You don’t have to worry as long as you are not told the passphrase was incorrect. Seeing multiple requests for your passphrase usually only occurs once per SSH key.

In the event that your push was complete, you should be greeted with a window similar to this:

Git Gui Stage

A Small Guide to Git and Deployment

Before I let you go, here’s a list of fantastic resources for continuing your Git learning.

Tags: git
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://gustavobazan.com GuSS

    Considering this alrady exist http://windows.github.com/ I think is silly a post like this

    • eric

      agree,

      maybe I missed it but this is written as if the new Windows Git Client doesn’t exist. This should have been written to show the differences between the new client and these previous solutions and the pros, and cons for both.

    • http://www.rommelxcastro.com Rommel

      i think the tutorial must be focused on GIT, not on Github, so is fine is they don’t use the Github software

      • janw

        True, but then the article should point the difference out.

    • hardik

      I agree. New windows client for git is awesome and its far more easy.

    • http://khaledgarbaya.net khaled

      i thought that you will talk about the new git for windows app -__-

  • http://www.lamplightmedia.net Casey

    I’m a HUGE believer in TortoiseGit. The git GUI client is rather bulky and takes too many steps in my opinion.

    http://code.google.com/p/tortoisegit/

  • Wilson

    Sorry but this software really sux … I can’t use it after command line git …

  • http://spirit55555.dk Anders G. Jørgensen

    Why not use the GitHub for Windows (http://windows.github.com) program?

  • Nadav

    Great tutorial! I’ve been looking over the previous tutorials and didn’t understand why no-one is creating a tutorial that’s using a GUI.

    I have had many problems with learning Git this week, and this tutorial helped me a lot. I have a tip: Int the tutorial you didn’t mention that the username is CaSe SeNsItIvE. I’ve tried using my username only with lower-case letters, and I’ve got “no repositories found. fatal error: the remote end hung up unexpectedly” or something like that. Just removed the origin and added again. This tutorial is very easy to understand. Thanks!

    • http://rommelxcastro.com Rommel Castro A

      believe me, the console is a better tool ;)

  • Mark

    Hey, I don’t wanna be a buzzkill, but that is from the past already.
    Here is the new Git for Windows: http://windows.github.com/

    • http://www.teacupspuppies.com/images/BumbleBee.jpg Mr Bumble

      Total buzzzz kill…

    • http://johnnyfreeman.us Johnny Freeman

      Hey, I don’t wanna be a buzzkill either, but the title of this article is “Git on Windows for Newbs” not “Github on Windows for Newbs”. :)

      Not everyone uses Github for every project.

  • http://faisonz.com Faison

    Great tutorial, It’s cool to see that the Windows Git GUI can actually be useful! I like how you generated the SSH key with the GUI rather than the CLI like I normally do.

    There must be a lot of people thinking about this topic lately, because I just posted a guide last week on setting up Git and GitHub for Windows for use with Bitbucket.

  • David D’hont
    Author

    Just to clarify. This tutorial was sent to Envato, about maybe 2 days before the Github Windows Client came out. So no, it wasn’t to show the differences. However, you seem to forget that github is nice and all, it’s not the only Repository hosting out there.

    I use Github now more because of the client, so that was a nice move they made. But that doesn’t mean there shouldn’t be a way to interact with any repository hosting other then Github.

    @casey, to be honest I guess that’s just your opinion. But in the end I think that the Windows GUI for Github actually beats either either one.

    But in the end, Envato has all the variations of all Git articles, thus more traffic for them.

  • Nic

    Is there going to be a Git on Mac tutorial to follow this one?

    • http://developernetwork.info/ David D’hont
      Author

      @Nic I doubt it. There are tons of Mac tutorials out there for Git on Mac, and NetTuts Premium is working on a new and more complete one. Most likely it will be on a mac. And it should as far as I can see cover all the things if not more then were covered here already.

      If you want to get started right away without messing around in the console, I suggest taking a look at Chris Coyier’s Mac tutorial for Git Tower, which would be pretty much a Mac Equivalent of the program that I used on Windows.

      Jeffrey told me that he’d use this a more of a quick tip to get started on Windows, but it’s been done. So I doubt you will see more Git anytime soon.

      Personally, I have a firm belief that you shouldn’t care what has been done already, as long as you can do it better. But I can understand where they are coming from.

  • http://hcgdietf.multiply.com/journal Beauty Tips For Hair

    Hi Dear, are you in fact visiting this web site on a regular basis, if so then you will absolutely obtain nice knowledge.

  • http://msfx.co.uk MSFX

    Personally I find the console far faster to use… just my 2c

  • Khalil

    Successfully passed the 3rd Step, but in the Step 4 I am stuck when I click “Commit” button I get error window.

    Unable to obtain your identity:
    *** Please tell me who you are.
    Run
    git.config

    • David D’hont
      Author

      @Khalil, This is a problem that sometimes happens. If you haven’t been asked at some point to fill in your real name and email address. You can do so by going inside one of your repositories and clicking:

      Edit > Options, you will see 2 form holders with the exact same contents. The left being the settings of the current repository and the right being the global settings.

      Here you want to make sure that you input anything in username and email. I think it might has to be the same as the service you are connecting to. But it could also be absolutely just for no reason at all. Whatever the case. Don’t leave it empty and save your global settings.

      If you even seen a Linux or Mac tutorial, you may have actually seen these words before. They have to be setup before you can push or some nonsense like that… well, that’s Linux for you right there.

      • Khalil

        Thanks @David D’hont, it helped me. My first repository has been created successfully, now in my github repository there is a screen which is showing me some configuration file like

        ********************
        Global setup:
        Set up git
        git config –global user.name “Khalil”
        git config –global user.email zarpio@gmail.com

        Next steps:
        mkdir test-repo
        cd test-repo
        git init
        touch README
        git add README
        git commit -m ‘first commit’
        git remote add origin https://github.com/zarpio/test-repo.git
        git push -u origin master

        Existing Git Repo?
        cd existing_git_repo
        git remote add origin https://github.com/zarpio/test-repo.git
        git push -u origin master

        Importing a Subversion Repo?
        Check out the guide for step by step instructions.

        When you’re done:
        Continue
        ********************

        when I click Continue it is not going anywhere.

        Please help me and let me know, how can I put my local repo files into this repository.
        my github repository url is https://github.com/zarpio/test-repo

      • Khalil

        Dear @David D’hont,

        You are awesome, I was really trying to learn git and git repository but your post helped me a lot.

        Thanks

      • http://developernetwork.info/ David D’hont
        Author

        You need to add your Origin, the step is presented right there in github.

        git remote add origin https://github.com/zarpio/test-repo.git

        For more information I’ll simply refer you to the “pushing” part of this tutorial.

    • David D’hont
      Author

      @Khalil Your welcome :)

  • http://benjaminjfisher.com Benjamin

    What you have here is great, except that it seems to be missing half of the information a new user will need to actually work with Git. Is there going to be a Part 2 which explains fetching and merging?

  • Abdallah

    Thank you @David, but i still love the command line :)

  • http://twitter.com/jitendravyas Jitendra Vyas

    I’m not getting the same screen as you are showing for the step “Create a Local Repository”. I think GUI is difference. I downloaded it from here http://git-scm.com/

  • Mohannad Al Khasawneh

    Thanks , helped me ALOOOOOT !!! , great job!

  • Dave

    There appear to be numerous missing steps that will leave newbies scratching their heads. Anyone know of a good tutorial that has been tested?

  • Selene Arzola

    Like a windows user that i am i must confess that at the star it was hard to me to know how can i configurate it, i mean user license,ssh keys etc so thats why if you find in the same situation that i have found please take a look at the github:help (https://help.github.com/) its so helpfull and well explained =)

  • Selene Arzola

    Like a windows user that i am i must confess that at the start it was hard to me to know how can i configurate it, i mean user license,ssh keys etc so thats why if you find in the same situation that i have found please take a look at the github:help (https://help.github.com/) its so helpfull and well explained =)

  • http://twitter.com/fikri1510 afikri

    Thanks, this is perfectly what I am looking for