Git command is taking wrong user? To solve – check CredentialManager

Yes, this was a strange scenario for me. I created Angular 2 project in Visual Studio Code and wanted to push the project into a GitHub Repository. Sounds a simple requirement right? So to publish the project to a GitHub Repository, I ran following 5 commands in the order given below:

  1. git init
  2. git add –A
  3. git commit –m “commitmessage”
  4. git remote add origin “Url of GitHub Repo”
  5. git push origin master

For the push command, I got the error as shown in the image below. Focus on error message for user djinfragistics

image

Error message is very clear that user djinfragistics does not have access to the remote repository hence HTTP Error code 403 is returned from the GitHub server.

To check current user name for the project I ran the command

  1. git config user.name
  2. git config user.email

As shown in the image below, I found username and user email was set to the user which had access to remote repository.

image

I was confused and was not able to figure it out that why git command is not taking user from the current project and taking some random user djinfragistics. I thought might be global user is set to djinfragistics. So, to check that I ran the command as below

  1. git config –global user.name
  2. git config –global user.email

As shown in the image below, I found username and user email was set to the user which had access to remote repository.

image

It was strange, that global user is also set to the different user, however to publish project, git was taking some strange user djinfragistics from somewhere.

After bit of researching, I found that on windows when we install git 2, Credential Manager also gets installed. It runs as a daemon process and caches the git user credentials, such that each time we do not have to provide user information to push the changes to GitHub repository.

In my scenario, I might have used djinfragistics username earlier on the same system and that user got cached in Credential Manager. So even though user was set to debugmode, on running the command git was taking user djinfragistics from credential manager.

To check various options, run the command as shown below

  • git credential-manager

Above command will show us all options of credential manager. I was lazy and wanted to publish project as early as possible, so I ran

  • git credential-manager uninstall

image

The above command will uninstall credential manager and we will have to provide git user credential each time. I would recommend you to explore various options and edit the file rather uninstalling it.

It solved my problem and git command started taking correct user name. I hope it helps.

Working with GitHub Repositories and Visual Studio 2015

Read full blog post on the Infragistics Blog

GitHub is one of the most popular code sharing platforms, following the GIT algorithm for version control. In this blog post, we will learn how to work with a GitHub repository and Visual Studio 2015, and will answer the following questions:

1. How to sync or share a project from Visual Studio to a GitHub Repository

2. How to clone a GitHub Repository in Visual Studio

Syncing or Sharing project from Visual Studio in GitHub Repository

To share the project, let’s take the following steps:

Step 1: Start with creating a Repository on GitHub. To do that navigate to https://github.com/ and click on the + sign to create a new repository. In this example, I am assuming that you have already created an account in GitHub.

image

Next you need to provide information including:

  • Name of the repository
  • Description of the repository
  • Whether repository is public or private
  • Whether to initialize the repository with a README.

image

Make sure not to initialize the repository with a README. If you do so, you will encounter errors while syncing the project to the repository. Once the repository is created, click on Clone or the Download dropdown and copy the web URL as shown in the image below. We’ll need the GitHub repository URL later in Visual Studio.

image

Step 2: Install Git for Windows on the machine. You can download this here: https://git-scm.com/download/win. After downloading, follow the screens to install completely.

Step 3: Open the Visual Studio solution you want to publish to this GitHub repository in Visual Studio. In the Visual Studio Solution Explorer, right click on the solution and click on Add Solution to Source Control.

image

 

Read full blog post on the Infragistics Blog

How to Clone a Git repository in Visual Studio

In my trainings, often I get a question from junior developers that how to clone a Git repository in the visual studio? Perhaps it may be very simple for senior developers, however for the developers who struggle to get it right steps are discussed below,

Step 1

Find the URL of the remote git repository. For GitHub repository URL can be found as shown in the image below. Copy the URL from here.

image 

Step 2

Launch Visual Studio and from the View select Team Explorer. In the Team Explorer window select Clone.

clip_image002

On clicking Clone, you will get an option to provide the URL of the Git repo and the choose folder in which repository will be cloned. In the URL section paste the remote repository URL as whon in the below image:

clip_image004

As the last step click on the Clone and the remote Git repository will be cloned in the Visual Studio in the given folder. If everything goes right you will get success message as shown below.

clip_image006

I hope it helps. Thanks and Happy Coding.

An error was raised by libgit Category =Ssh error: solved git for Visual Studio

Have you come across the error as shown in below image?

clip_image002

You get the above shown error in Visual Studio while pulling changes from the git server. This error causes because you have local changes without the commit. In this scenario the visual Studio does not give very readable error message. Perhaps you may want to use git command for pull for more information on the error.

clip_image003

The git pull command clearly says that either commit the changes or stash them. If you are not sure about the local changes then better option is to stash them. Local changes can be stashed using the git stash command.

clip_image004

After stashing the local changes (you can commit also) run the git pull command to pull the remote changes from the git server. You should not get any error doing pulling the latest changes.

Hope it helps. Happy coding.

How to use DebugView to Log Entity Framework

In this post I will show you to use DebugView to log the Entity Framework. For detail discussion on the same topic you may want to learn more here:

Logging in Entity Framework on Steve Smith Blog

Profiling Database Activity in the Entity Framework by Julie Lerman

Download DebugView , unzip it and Run it as administrator. In Capture menu select the options as shown in below image,

image

Once the debugview is configured, you should configure the DataContext class as shown below. Enable database log to print on the debug window.

image

As the last step run the application using Entity framework without using Visual Studio or without attaching Visual Studio Debugger. In Visual Studio run the application using Ctrl+ F5. You should able to view the Entityframework log in Debugview as follows:

image 

The Debugview can be your good friend when you stuck with performance issues and want to log the queries.

Happy Coding.