Using GIT With Visual studio online from the command prompt
GIT is, in contrast with Team Foundation Server, a distributed version control system and becomes more and more a de facto standard for source control handling.
Quite often GIT is used in combination with GitHub as remote repository. In this article we will use GIT together with Visual Studio online.
Since I’m doing more and more projects based on the MEAN stack, I’m getting again addicted to the command prompt. So, although there are some nice GUI based tools available for working with GIT, we’ll just use the command line.
Currently, I’m sticking to TFS based repositories for my visual studio based projects. For all my other work when using the MEAN stack (for which I do not use visual studio), I use GIT. For these Mean stack based projects I use WebStorm, which has decent GIT integration. Maybe I’m missing all the comfort WebStorm is offering here, but for the moment I just feel ok with the command prompt. The advantage is that if I switch maybe tomorrow to another IDE (or editor like SublimeText) I don’t need to learn new tricks.
Command line tool
Download the Git command line tool and install it. It will take less than a minute.
Preparing visual studio online for GIT
You will need to go online to your visual studio online subscription and create a new team project and make sure you select GIT as version control system rather than “Team Foundation Version Control”.
We also need to create alternative credentials in such way we can login to the GIT repository in visual studio online from the command line. So, you cannot simply use your liveId. In order to configure these alternate credentials based on “basic authentication”, you’ll need to find on the right hand site of the visual studio screen, the my profile page:
Then go to the Credentials tab and create the alternate authentication credentials:
Remember these credentials, because you’ll need them in a minute.
That’s all on the online side.
What is the Url of my GIT repository?
So imagine your visual studio online account is called “MyAccount” and you created a new project “MyProject, then the entry point is:
But, the URL of the GIT repository in visual studio will have following format.
We’ll need this last URL when we will clone our newly created remote repository locally.
Basic GIT commands
Following commands are the strict minimal you need when working with GIT
Clone the remote repository locally
So, make sure to use and Url in the correct format (with the _git subPath). When cloning a remote repository, you will be asked your credentials that created earlier. Note that when using GitHub you can clone public repositories without specifying userName/password. Quite obvious, given they are public.
Note also that the process of cloning a repository will also take care of creating a parent folder for your project. So, since the above repo is called “MyProject”, it’s not necessary to first create yourself a parent folder for this. Just go the folder where you store all your GIT local repositories and execute over there the git clone, which will create the “MyProject” folder for you. What is very important is that after cloning the repository you need to step into that newly created folder by typing
Create an empty Git repository
You’ll not need to do a git init when you cloned a remote repository.
Add file contents to the index
This command will figure out what changed locally and prepare things for the next step, the actual local commit.
Record changes to the repository
So, note that it’s a local commit. In the next step we’ll push things to visual studio online.
Update the remote repository
You will be asked again for credentials. “Origin” refers here to the remote repository.
I want to know everything about GIT
Download the free Apress book.
Using GIT feels good. It’s rock solid and versatile.