Up and Running with Git and Visual Studio with Azure DevOps

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi it's bill Raymond in this video I'm gonna show you how to use Visual Studio with Azure DevOps repos let's go ahead and get started you as always I'm going to start with a few slides first to get you up to speed and then we'll go into the demos you can look at the description below if you want to find out where the demo start so as your DevOps is actually a full platform for managing your development lifecycle this as your boards pipelines artifacts test plans and Azure repos we're gonna focus on Azure repos in this video I do have other videos and I just actually published one on adjure pipelines so you might want to check that out a repo or repository is where you put your code for your solution now you might have multiple repos for one solution or you just might have it all packaged up in one solution it's up to you but the point is is that each repo is a package of code and you define how you want that packaged now with Azure DevOps you can have multiple sets of repos and you can achieve that by setting up multiple projects here's where things get a little different than github for example you can set up a project and have multiple repos in it and then all those projects roll up to an organization let's take an example let's pretend like we work for Microsoft for a minute here that would that might be our organization and then underneath our organization we could have a project or multiple projects so for example we might have a project for Microsoft Word another project for Microsoft Excel underneath this word of project you could have repos for word for mac word for windows and word online or you could just have one project called all projects and you can have all of your repos in there for your entire organization so maybe Word Excel PowerPoint Xbox everything is just under one giant organization and one giant project you have to define how you want that set up so what's the difference between Azure DevOps and github well as you can see as your DevOps allows you to you have a lot more control around the organization and structure of your repos the security as well with github you basically have your organization or you and then you just have a list of repos so it's not really quite set up to have the advanced organization structure is as your DevOps so how would you use Azure DevOps you'll probably just set up an organization under your name or your business you'll have a project and you'll put a bunch of repos underneath that you don't have to do it this way but that's how I do it with my organization because I'm just a small business it's just me and a few people now one thing that you do need to know is as your DevOps as an enterprise application unlike github which certainly organizations use it to manage their enterprise code and they use private repositories but you as an individual and most of the the world thinks of github more as a platform for sharing code amongst other people and that's where github is really powerful with Azure DevOps you can make your repos public or private and both as your repos and github do offer free tiers which is great now here is the thing though with Azure develops it really is an enterprise app there is so much that you can configure and tailor to meet your needs and it's broken up into these different applications but they're all kind of contained within one web application look and feel if you want me to do more videos about how to configure Azure DevOps and you know for example boards and user stories and epics and configuring all of that let me know in the comments I'd really like to know if you're interested but for now we're going to jump into how we can use Visual Studio get in Azure DevOps repos as I mentioned at DevOps has a free solution for you so just go to a sure Microsoft comm and sign up once you've signed up for Azure DevOps you'll get a URL an organization and a project now you can create as many projects as you want you can even create multiple organizations but I recommend you just start with the organization and start with the project you can of course see when I mouse over there's a repose icon and if I click on that you'll see it goes to a URL it says underscore get slash Bill Raymond and you can see here it's it says that it's empty add some code so that's what we're gonna do next if you want to create your own project before you get started you can definitely do that but remember one project can have multiple git repos underneath it to get started we're gonna run Visual Studio 2019 and click create new project in my case I'm going to create an asp.net core web application you can search for that up here at the top click next and create it and now that it's created we'll go ahead and run it just to see what it looks like and depending on the version of Microsoft Visual Studio you have and what project you selected you'll probably have something that looks like this there's a welcome page and a little bit of scaffolding with some links to get us started before we do anything to our code we're going to add it to a git repository now you can have a git repository local on your computer so come down here to the bottom right hand corner of Visual Studio and click this Add to source control item and choose git now you might be asking me well wait a minute bill I thought we were using Azure DevOps well we'll get to that in just a moment but keep in mind that git is the way in which you'll manage your projects source control it's an open source source control solution and Visual Studio and Azure DevOps support it there is also visual sourcesafe but that's a conversation for another day okay we can see that our code is in source control because there's this master branch item here and down in the bottom right as well it shows our web application one with the little get icon next to it also the team Explorer displays here if you don't see the team Explorer now is a time to put it on your screen go to the View menu and choose team Explorer ok good now you should have this page that says push to add your develop services publish to github maybe some other repositories well of course we're going to use Azure DevOps here and we're gonna publish that git repo so I'll click this button here and once it's created you're gonna see that it has your user name the organization and the repository name so it says the organization is dev a sure to come slash Bill Raymond well let's go to the website for a minute and look at that as your URL it says dev - comm slash Bill Raymond there is our organization that's cool but what about the project I could have multiple projects here and have repos underneath them so where's the project click the advanced link in Visual Studio and now you can see that's where you can select the project finally it asks you for the repository name I recommend you keep the repository name as the default this way our project which is also called web application 1 is the name of our repo our repo so click publish repository now we see web application 1 was pushed see it on the web let's go ahead and click that link and there's our code if I come down here to web application 1 in two pages and to the index page you can see there's our welcome page right here now I'm going to leave here leave this tab for a minute and come back to the original Azure DevOps page that I was showing you now remember we have a project and we can have multiple repos under it I'm going to click the project now and you can see here it's kind of a little odd where is that project that we just that repo that we just created well remember that Azure devops is a bigger application so there's a lot more to it what we want to do is go to repos so if I click the back button again and I hover over here it's better to just click this little icon that brings us right to repos and that brings us to the same place if I had clicked on the project then I'll have to come down here to repos and now I can see it but let's take a look at this repo for a minute here you can see it says web application one and there is this get attributes and get ignore and this web application one SLN file let's head back to visual studio and go to our solution explorer where's that get ignore where is that solution file well it turns out and you're gonna find yourself doing this a lot when you're using git especially you're in the solution view right now a project view it's kind of giving you Visual Studio is giving you a nice layout to work with your code in a way that in this case dotnet likes to see everything laid out well if I come up here to this icon in the solution Explorer that says switch views I can choose folder view and now I can see there is my good attributes get ignore and the web application one SLN even though they're not in that project view notice that there are still little locks next to them so everything in the folder not just this view is under source control okay so let's talk strategy here I want to change the code in one of my pages so I can expand pages and come over here to the index file and now I want to change this welcome text to hello world I can just go ahead and make that change and save it as all good but really what I want to do is make sure that I follow some best practices now if it's just you working on your code and it's not a large solution and you can just make that change without worry go for it but a good way to kind of follow best practices is to say I have a package of changes that I need to make might be small might be a little bit larger but they're all kind of related what you want to do is create a new branch and then make your changes from up from that branch so we can do is come down here to this little master icon and then you can just go ahead and choose manage branches and add it or you can do the same exact thing which is to go to team Explorer go to branches ok and then click new branch both of those options bring you to the same place and so I'm gonna work on a branch called update index file and click create branch now I know that update index file is selected because here in the team Explorer you can see it's in bold I also know that it's selected because down here on the bottom right this is the branch I'm in right here you can see it says update index file so you'll not not always have the team Explorer displayed but you will most likely be able to notice it down here in the bottom right so pay attention to the branch that you're working on before you make any code changes right so let's make our change so it says welcome I want to change this from welcome to hello world and let's just go and run it I'm not gonna keep running the code because this is pretty much the the only change that we're really making but let's just make sure that it does indeed run perfect we have our hello world text in our app now so we can go back to visual studio at this point you kind of just staged the change you haven't really did a commit so that it's committed to source control what does that mean let's take a look at this index file here and if I hover over it says pending edit this little red check box what this is telling us is that while you made the change and you were certainly able to run the code and test it the change is not really in your source control environment yet so if I right-click on the index file you can see undo and undo is don't think of this as control Z undo this is undo all changes that you made to the file whether you exited visual studio and came back in later or not you can undo anytime there's a little red check box I can commit I can view history I can even compare now this is a really cool feature if I compare you can see on the left hand side there's our welcome text and on the right side there's our hello world and you can see any changes that we make get highlighted I'll close this point that we want to make here is it or rather what we want to do is right-click on the index file and commit it and here we're gonna make a commit message so I'll just type changed index file welcome text to hello world and then choose commit all now at this point you've made the changes on your local machine notice it says sync to share your changes with the server this is what's important to know about working with git you make your changes locally on your computer and then you push the changes up to Azure DevOps this is not automatic you have to decide when you're gonna do it conversely any changes that you make and add your DevOps will never come down to your computer you're gonna have to sync those down so I'll click the sync link and you can see it brings me to this page but what if you don't have that sync like you had moved around just click the home icon and you'll find the sync option and then you can just push that out going commit so you have a commit that you made on your local computer and this is our outgoing commit to upload to Azure DevOps I'll click push and there so now we should be able to go to Azure DevOps to review our code now here we are in Azure DevOps and I'm gonna mouse over my project and then click on the repos icon and you can see it says Bill Raymond is empty add some code well we just added some code so why is that well that's because you can have multiple repos so I'll click on this pick list here at the top and choose web application one and there now you can see the code is up here in your DevOps so I'm gonna go ahead and click on that folder and go into the pages and take a look at the index file and I'm going to look and see our HelloWorld nope does it look like I'm saying the hello world text it still says welcome well why is that that's because remember we have two branches and our code one of those branches is the master and then the other one is where we have made our changes in our application so if I come up here to the top left and I click on the master pick list you can see there's the other branch that has the hello world text so you can go ahead and select that what you need to be aware of is this pick list does not always update as quickly as you'd like so if you don't see your branch that doesn't mean that doesn't exist just come over here to this branches icon and click that instead good news is our branch is showing up so go ahead and click that and now you can see there's our hello world text now remember we're still in this update index file branch and if I click here and go to master you can see at the master it still says welcome but when I switch back over here to the update index file branch it says hello world now it says update index file so that's what we're doing now I change it to hello world and my peers said well I don't know about that can you change that to hi there instead so I'll just go in here and say instead of full the world hey there and I'll save that and remember nothing's changed quite yet until I commit that in the index file so I'll right-click and choose commit and then I'll say changed index message to hey there and commit that there I'm not gonna sync this up to Azure DevOps quite yet now what happened I made this change and someone said oh wait bill no we need to put it back to hello world just ran it by legal we need to put it back so I could of course make that change and commit it again but let's take a look at one other option I can come down here to this branch area here and say view history and so I'll go ahead and do that right now and what you can see is a list of all of the things that have changed in the code here's where we changed it to low world and here's our hi there so if I don't want hi there in there anymore I can just right click and choose revert and say yes now what happened well it did revert but it doesn't look like it did so I'm just going to come up here you're gonna like this history and I think you should remember that it's here and and use it frequently when you're trying to figure out like changes that you made in your code however when you do a revert or some other actions in this page you will have to use this refresh icon so I'll refresh and now you can see that there was a revert that occurred so what happens I reverted the hi there change so my code should now go back to hello world let's take a look and see sure enough there it is there is a hello world now at this point we're really comfortable with our code and we want to get it into the master branch so how do we do that what we'll do is come over here to our branch and set it to master it still says welcome so what I'll do is come up here to the Home icon in the team Explorer and I'm gonna say branches I'm going to click on branches and you can see master is selected and I'm going to choose a merge from branch update index file so we're going to go from the update index file into the master watch now as is welcome text changes after I merge there now it says hello world in the master so basically master an update index file match at this point we want to upload our code up to Azure DevOps because we now have our master branch updated so it's real important that we do that so we'll click the team Explorer tab here and once again if you don't have that go to the View menu and choose team Explorer click the Home icon and choose sync you'll notice all of the changes that you've been making including the revert are all here so just go ahead and push those out and good you're all set this is where I store my code it's under source repos and you can see there's a web application one that's one we've been working on now maybe I accidentally deleted it formatted my hard drive computer was stolen or I never even had this code because someone else was working on it and asked me to collaborate either way I need to get it from Azure DevOps down on to my computer so I'm gonna remove this from my computer right now there so now visual studio won't be able to open it because I deleted it when you run Visual Studio 2019 you'll get this get started panel now sometimes people disable this so I'm gonna show you how to clone or check out code from the visual studio user interface but do know that the same option is right here there's no difference so I'll choose continue without code and go to the file menu and choose clone or check out code you can see here I can enter a remote git repository or I can just choose as your DevOps so I'll go ahead and click on that then I'll choose web application 1 and click the clone button so what I'm doing is downloading all of the code from measure DevOps down to my computer there it's been done now you can see here's that get attributes and get ignore where is that nice layout that I should expect from Visual Studio well remember I have to click on the switch views option and then go to the solution view and once I do that you can see all my code is here it's in source control and if I even come down here I can verify it's in source control see web application one has a source control item next to it and there's that master branch that we were working on if I choose view history you can see here's all that work that we did ok so we didn't just pull down the master we actually pulled down all of the code including any of the changes that we made back in Azure DevOps I'm going to go to the code from my project so I'll hover over the card for Bill Raymond click on the repos icon and then just make sure web application 1 is selected and it is now what I'm going to do is create a file up here in Azure DevOps I'll click the new item and choose file almost every repository should have a readme file and what do I mean by almost well it does I guess technically you don't need a readme file but it's recommended and you call it readme dot MD MD stands for markdown which is like a simplified version of HTML so I'll go ahead and click create and then I'll just type in this is my up welcome I can just go ahead and type whatever I want the point here isn't necessarily that we're creating the readme file though this could be useful for you the real you know by the way if I click preview you can see there that's what it looks like in markdown but the real thing that we're looking to do here is to make a change on the web and then bring that down to our local Visual Studio app so I'll go ahead and commit this I'm gonna commit it to the master branch I could have created a new branch and then merged it after that was done but I'm just gonna go ahead and add that to my master branch there back in visual studio we can go over here to the folder menu and take a look we do not have that readme file even though it's up in Azure DevOps why is that well remember everything you do with get you have to decide there's nothing automated here when you want to add code you have to know whether you're gonna create a branch or not when you want to publish something up to the server that's your job when you make a change on the server you decide when you're gonna pull it down or if you ever will okay so here we have this area where we want to get the readme file so I'll go to team Explorer and then I'm gonna go to sync and click sync there that's been done so now let's go ahead to the solution Explorer and there's that readme file if I open it up you can see there is a text that we just entered okay now that we're done with this session I'm going to just walk you through a few tips and tricks remember that you do have your organization link over here and your list of projects you can click on the project and to get to repos you click over here you go to files but remember if you're at the organization level you might as well just hover over the card and choose the repos icon that will get you there faster also remember that sometimes this pick list does not refresh as quickly as you might like so if you can't find the branch you're looking for just come over here to the branches icon you have to have the azure repose icon selected but then you'll have a branches option and this will allow you to get to the one that you're looking for and finally remember in Visual Studio all of your code underneath the folder that you're working on is always under source control whether it's the individual files or the things that you see in the solution view remember to get between the solution view and the folder view just make sure you're in this solution Explorer tab and then click this icon up here to toggle between the solution view and the files view thank you for watching this video if you want more like this please like comment and click the bell to support my channel
Info
Channel: Bill Raymond
Views: 32,066
Rating: 4.965167 out of 5
Keywords: azure devops, devops, git, visual studio, visual studio 2019, training, up and running, bill raymond
Id: sntGDmwA7yw
Channel Id: undefined
Length: 28min 6sec (1686 seconds)
Published: Tue Oct 22 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.