Getting started with Git and Visual Studio

GitVs_01 (1)

I use Git with Visual Studio. But I don’t use the GUI,I just keep a command line open as well as Visual Studio. (We are developers and we love typing code )

But here a nice GUI tool that integrates git with Visual Studio

Introduction

This post talk about how to make a simple environment to personal source control with Git Bash, Git GUI and Visual Studio 2010

Some Basic Git Concepts

What is Git:

Git is a distributed version control system that records changes of you software projects.

Repositories

A Git repository is simply a database containing all the information needed to retain and manage the revisions and history of a project. **

Commits

In Git, a commit is used to record changes to a repository. **

Branches

The best way to understand what is a branch is doing commits, when you commit in Git, Git stores its data as a series of snapshots. “Every time you commit, in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.” ** If you make some changes and commit again, the next commit stores a pointer to the commit that came immediately before it. A branch in Git is simply a lightweight movable pointer to one of these commits. A branch often represents an individual customer release. The default branch in a repository is named master

Installing Git (msysGit)

First, download the latest version from: http://code.google.com/p/msysgit/downloads/list After the download completes, run the installer

GitVs_01 (2)

For easier msysGit run, check the two pertinent boxes, to add in the Windows Explorer, as shown

Let’s get started

Git is simple to use. Go to All Programs and open Git Bash

GitVs_01 (3)

Or just open a Command Prompt and type Git.

Configuring the Commit Author

Before making many commits to a repository, you should establish some basic configuration options.

  1. Start Git Bash
  2. git config –global user.name “Your Name”
  3. git config –global user.email “your@mail.com

Create a new Visual Studio Solution with a project (for this example a Silverlight application)

GitVs_01 (4)

Write Code and Save Changes or run the application (F5)

< Rectangle Width="300" Height="100" Fill="Red" />

GitVs_01 (5)

Creating an Initial Repository

Go to solution folder and select “Git Bash here” or at the Command Prompt type “cd path\to\your\solution\folder “

GitVs_01 (6)

To initialized empty Git Repository in your path

GitVs_01 (7)

At Command Prompt Type:

  • git init
  • git add .
  • git commit –m “first commit ( with a rectangle )

Now to get a UI tool Type: gitk We have a first version of our application

GitVs_01 (8)

Now let’s make some modifications

We can add more files (class, service etc.) and commit this changes

< Ellipse Width="300" Height="200" Fill="Purple" />

GitVs_01 (9)

Save changes in Visual Studio and add the change to Git

Making another Commit

At Command Prompt Type:

  • Git add .
  • Git commit –m “Change to Ellipse And so on for other changes in your solution

Viewing the Commit History

Once you have one or more commits in the repository, you can inspect it

At Command Prompt Type:

• Gitk

Our History of changes:

GitVs_01 (10)

What happen if we want back to first commit?

Simple in gitk select “Reset master branch to here”

GitVs_01 (11)

GitVs_01 (12)

Next Visual Studio will detect the changes and reload the solution

GitVs_01 (13)

GitVs_01 (14)

We Back to First Version

GitVs_01 (15)

We can back to other version commit

GitVs_01 (16)

GitVs_01 (17)

GitVs_01 (18)

GitVs_01 (19)

The .gitignore File

You can skip any file by adding its name to .gitignore in the same directory.

For this example in visuals studio , Those are irrelevant files:

bin/ |obj/ |_ReSharper.* |*.csproj.user |*.resharper.user |*.resharper |*.suo |*.cache | *.user |~$*

As you have seen, git is awesome, faster, has ability to handle large projects, distributed, no heavy services or relational database to stored data.

There are lots to learn, but at the moment that’s all folks.

References:

** Version Control with Git: Powerful Tools and Techniques for Collaborative Software Development

Leave a comment

Filed under Develop

Leave a comment