Git Fundamentals

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi welcome to visual studio tool box I'm your host Robert Greene and on today's episode we're going to look at git git is a distributed version control system and has become very very popular so we're going to look at what git is we're going to look at how it works now as I'll say repeatedly throughout this episode git is plumbing its how the version control actually occurs then we're going to see how you can use it inside Visual Studio and we're also going to take a look at places where you can share code with others github visual studio team services both have great support forget you'd obviously expect github to have great support forget but it turns out visual studio team services does as well so we're going to look at some of the basics of git we're going to start out looking at the very very high-level basics of what it is and how it works and then we'll switch over to visual studio and run through some examples where we work with an actual project or two and see how to do source control using git this episode is going to be about an hour long but I think at the end of it you'll have a really good understanding of what git is and how to use it so as I said it's a distributed version control system and the cool thing about that is it's not the what we might be used to where we have a server which has the main level of our code the main version of our code and then we want to work with something we have to go to the server get code back if we want to do a commit we got to go to the server and get code back github is distributed which means that everybody who's using it has locally a complete version of the source code and all of the history of commits and etc so that means it's very very fast because the bulk of what you're doing happens locally it also means that you can work offline so if you're on an airplane or a train or something you can work with your code and then later on move that code into a more central location to share with others it also means that everybody has a backup of the entire system because it's all local right now--get is plumbing so let's take a look at some of the basics of what you can do and for that I'm going to use the command line if you watch the show and know me you know I'm not a big command line guy but I think but the basics of git that's the way to go so I'm going to start off very very simply right I have a folder get repos and in that I have a command line folder and I'm going to work with some code that's in here right so right now git repos backslash command line is just a folder I want to turn it into a git repo which is short for repository a git repository is a place where you store code or something you're tracking and I've told get that I'm going to have source code in here and I want you to track it for me okay so to turn this folder into a git repo we're going to run some commands so I'm going to go out and go to my Start menu and I'm going to use the git command there's get bashed is get GUI I got all of these when I installed get for windows which I let Visual Studio install for me I'm just going to use get command because oops I'm trying to move this there we go so first thing I want to do is move into this folder so CD into that folder which again right now it's just to fold it but if I say get in it I have now created a git repository so again repository is now a folder just a folder where I'm tracking the code I'm writing what's in this git folder it contains a whole bunch of stuff we're not going to spend any time looking in this but this is the history of the project all of the commits I've made we're going to see later on that code actually gets stored in there presumably in a very compressed format but now I have a git repository let's rearrange this so I can see both there we go so now I'm going to do a git status and we see I'm on the master branch I did an initial commit when I created this and there's nothing to commit there's nothing to do because I haven't actually written any code yet let's keep this really simple I'm going to use a text file I'm going to copy this my file dot txt file in here and now if I do a git status and spell it right then get says hey look there is an untracked file in here get knows there's a file in here it also knows I'm not doing anything with it it's not part of source control yet I want to start working with it is part of source control then I do a git add I add my file and now if I do a git status it says hey there's a tract file in there that is actually staged to be committed so this file is now available to commit so I'll do a commit git commit and the comment will be added my file okay so now if I do a get status nothing to do and if I do a git log I do a git log then I can see that the most recent commit that I did there is its unique identifier who committed it and when okay now I decided to keep working on these things I make a change to my file this is my updated file I'm going to add another file my other file into here now if I do a git status see that I have a new untracked file and then a change it knows that I made a change but it knows that I haven't staged it it's not ready to be committed so what I would then do is do a git add the changed file and my file the file I added now do a git status and it knows that there are two files ready to be committed I'll do a git commit changes to files again do the status there's nothing to do and do the log I can see both of my commits okay so now I've been working with these files they're perfect now I want to share them with other people so now I want to take them off my machine and copy them somewhere where other people can work with them if all I'm going to do is work with these files myself I can just leave them local but I want to share them with others a couple places we can do this we're going to look in this episode both using github as well as visual studio team services github it's a perfect place to share code with others because it's free to create a github account and it's free to create a public repository so here's my github here's my github github.com /ro green so here are some repositories I like to share a conference code here talks that I've given at conferences I'm going to look at repositories I have and I'm going to create a brand new repository to store the files we've been working with so I'll go to new now I'll just call it foo I'm not going to make any other changes to it I'm going to create the repository and now it tells me look if you want to pushed an existing repository import code from another repository or work with this repository locally here's some code alright so I have a local repository on my hard drive that's here unable to find the onedrive phone yes I know because do it onedrive for business is trying to sync in the background is trying to sync to my external hard drive which is not connected to this machine so we'll just ignore that message anyway we have our local repository here we have our public repository in github we need to link the two together so I can then move the files from local to the github repository and keep those in sync so to do that I could type the code or I could get clever and copy it from here so now when I do a git remote add origin with that URL what I'm now doing is linking up the local repository to the one sitting in github I can do a git remote - v4 verify and I can see that I'm actually linked up now what I want to do is copy these files that have already been committed locally I want to get those files into github so for that I do a git push and the comment here this sample here tells me to do a - you that's optional the - you just has github I'm sorry get remember where I've sent these to so I'm going to do a git push origin master which basically says take my local master branch and push it to the origin which is the master branch sitting up in my public repository I'm going to do that now if I go and look at code are the two files okay I can let's see I can look at the history okay there these were committed all right so that's kind of cool all right so now I've got this code sitting up and get shared with others and so other people might make changes to it so let's go into my file and let's edit this and this is and update to my updated file I'm going to commit that and now the version on the server is out of sync with the version locally because again local doesn't automatically inherit these changes okay so now what I need to do is get the code from github local so I'm in sync in a couple ways I can do that the first one is using a fetch followed by a merge and then after that we're going to see a pull so if I say git fetch origin master okay now what happens is if we look at this file this is not the changed version what get did was it brought down that file and it's storing it somewhere somewhere in this dot git folder but the version I'm working with hasn't been updated yet to update it I want to do a git merge origin master which fails because it turns out that to do the merge you got to say origin forward slash master okay now my file the local version has been updated to this update okay so you do a fetch to bring the changes down then you do a merge now you can short-circuit this so I'm going to come up here and make another change to this this is you another update to my updated file bit changes I don't have to do the fetch followed by the merge what I could do is a pull git pull origin master which does a fetch and emerge at the same time now this is another update to my updated file so when would you do one versus the other when would you fetch then merge versus pull if you do a pull it does a fetch and then does emerge and if there's a conflict then the pull just fails right if you do a fetch then you can kind of compare what's going on if you did if there's a conflict then you're going to have to do a merge but you're going to have to resolve the conflict so if you know that there aren't any conflicts if you just want to get the latest version then you can just do a pull if you think there might be conflicts or if you know there are conflicts we'll see examples of that later on then you want to do a fetch resolve the conflicts and then do the merge okay so and again just to review we did a git push origin master that we did to get merge which requires fetch excuse me we did a fetch which does not require does not use the slash in between origin and master we did the get merge which requires the slash then we did the pull which doesn't use the slash so push fetch pull don't use the slash merge does and I actually don't know why so if anyone out there knows why that's the case please put a comment in the show notes and educate us ok so now we have a repository we sync the local to the one on the on the in github let's look at another way to do this so let's go back to repositories and let's create another repository called foo - and this time notice that while we're in here you can make private github repositories but you need to have a plan with them that actually cost money so we're just going to stick to the public ones so let's initialize this with a readme write repo should have read Me's they should have these other things which we'll look at shortly so let's create this with a readme okay and now there's a readme file in there okay so now what I want to do is work with this same repo but I want to have it point to the food to repository and not the food repository so what I'm going to do so I'm going to say get remote remove origin and that breaks the connection between my local repository and the food repository that we created earlier and then what I'm going to do is do an ADD origin which hooks it up to the food to repository okay so now this local repository is synced to the other repository to the food to repository okay so now I want to get these files my file in my other file up into here along with the readme so I say get push origin master they've already been committed and that sales right we mode contains work that you do not have locally the server version of this the remote version of this has a readme that I don't have locally so these two repositories my local and the public one are out of sync so I need to get them in sync so I say oh all right well I'll just do a pull right git pull origin master fatal or failed refusing to merge unrelated histories because these things are not in sync the question is how do I get them in sync they have unrelated histories locally I just have the two files I have those two files but not to read me on the server and github I have the readme but not these two files they're unrelated histories how do I and the way you do that is to do the git pull master two dashes allow unrelated histories okay and now the read means down I've got the two files here and so now I can do a git push origin master and if I come back to here there we go now everything is in sync so in all likelihood you're going to create the repository then create the code in this case a little out of sync so I can get them back into sync by doing the allow unrelated histories now a third way to work with things is to clone a repository so the repository exists in github and I want to start working with it I don't have a local repository so let's go to here let's create a third repository we're going to call it booth 3 I'm going to add a readme okay then I'll create this so now I'm going to clone this so I'm going to go back up to the git repos folder and I'm going to say get clone HTTP sorrow green lips github are green boo three get that creates the food 3 folder and has the git folder in it and the readme so now this repository is synced with the one on the server because that's where it came from and so now of course I can do the things that I've always done I can copy these into here I can say git add my file txt my other file txt yes and they do wrong not a gift of course not because I am in the wrong place I do this all the time you think I would learn okay get add there we go now I do a git commit M added files now get push origin master now and now those files get sent up to the github repository okay so that is at the very highest level kind of get basics not all of the basics of course but those are basically the basics of how get work so we've looked at creating repositories also known as repos we've looked at getting files into source control we've looked at committing and pushing things up we've looked at pulling things down and we now have a basic sense of how you work with github to manage files now what we're going to do is go into visual studio and see how it works inside visual studio because the get tooling in visual studio 2017 which is what I'm going to use is really really good it's gotten better and better with each release it's really good in 2017 okay so let's clean up a little bit here we don't need this we don't need this anymore because I'm done with the command thing we're going to work with Visual Studio all right so let me launch Visual Studio first thing I want to do I'm going to create a new project but the first thing I want to do is create a git repo for it I can do that in github as we saw but I can also do it inside Visual Studio okay so what I want to do inside Visual Studio is connect to github I do that over in the team Explorer window and team Explorer is going to connect to and give me the ability to connect to existing github repos local repos so these are get repos that I have locally it also shows me visual studio team system projects that I belong to right so what I'm going to do here is not connect to anything that currently exists I'm going to click create under github going to create a repository called get test one want this to be located in get repos so we're actually going to need this back I closed it a little prematurely so we do need this because I'm going to create it right here and then Visual Studio is automatically going to add for me a git ignore file a get ignore file is a list of files that we don't want checked into source control so anything in your bin folder or your obj folder you don't necessarily want packages stored in source control you typically just want the source so the git ignore file is a list of things that won't get checked into source control and then we'll choose a license we prefer the MIT license for sharing code so I'll use that and now I'm going to create this repository we created let's go out to github and see if that's true here's get test one with a readme and a license and the git ignore so the git ignore is just a list of all the things that aren't going to be checked individual studio I'm sorry I checked into github and it's basically again the results of builds all kinds of stuff in here so we just want our code in there okay so also Visual Studio is created to get test-1 folder which is a git repo and it has the GUID ignore the license and the readme okay so now what we can do is create a new project so I can create a new project or solution I can click there or sometimes what I like to do is double click on this right to make sure that I really am connected to it which I am I'm going to create a new solution we're going to keep this really really simple so let's just create a console app and it Visual Studio knows to put it in get test one knows to hook it up to source control so let's say okay and build this ah em we have nothing of terrible interest I'm not going to add a lot to this I just want to now commit this and get it into github so if I go to the changes tab here I can see all of these files have been staged for committing now you can do everything all at once or you could do things individually let's say I just wanted to stage the program file program dot C F I can stage that and then that will be committed but nothing else or if I unstaged this now everything is ready to be committed and that's the way I'm going to keep it for for all of the demos we're on the master branch and I created the project will be my commit comic you should always comment your commits so I commit all okay now I can see that I commit it all because visual studio shows me that one author made a change if I click on that I can see this double click on it and go see more information on that commit but what I want to do now is get this up into github so I will go to the sync tab so I can do a fetch from here I can do a pull from here I can do a push from here using the same commands we saw earlier I'm just going to push this successfully pushed so now if we go to github look at code there's the solution console one I can look at the history and see that the commits all right when I created the project and I can come in here and I can look at all of the code in here okay I can also look at the history back in Visual Studio so under actions here I can view the history I created initial commit when I created the repository created project when I created the code and committed it okay so now this code is local it's also in github and those are in sync so what happens if somebody makes a change to this so what we're going to do out here in github is we'll edit this file code was added in get-tough going to commit and I'm when I'm in github I'm always going to not add a comment in here just if I was doing this for real I certainly would but I'm not going to the festive this session okay so now in Visual Studio I of course don't see that because the local version I have does not have the my local version is what I originally created doesn't reflect what's in up in github okay so now you is a fetch so I'm going to fetch master which brings that down but doesn't show to me because again it's sitting somewhere in that get folder when I now want to do is emerge so to get to the merge I go to the branches tab and here's the merge so now I'm going to merge from origin/master so this says merge the contents of the master branch up in github which is the origin with the contents of the master branch that I have locally on my computer and when I do that I will see the comment here okay so now go back into github and make another change to this code was edited in github commit that come back to visual studio and now what I'm going to do in the sync tab is a pull again that does the fetch and the merge all-in-one and then of course if I make changes code was added in vs then I can do the commit and the push which I can do from the team Explorer but I can also we look down here in the status bar this tells me that I have a change so I can just click on that and go straight to the changes tab edited code do a commit either click sink here or I can click this down here they both do the same thing it's just a question of my eyes are down here I like bees if my eyes are up here I use the shortcuts there and then I push this back to github it changes in visual studio so again if you're just working with the code yourself you can keep it all locally but when I put it into github it gives me the ability to work with others I'm just sharing the source code with you guys I may not want you guys to make changes we'll see later on how I would allow that but if or if I'm working with a couple of you on a project we could put the code in github and then we'd all make changes typically of course we'd be making them from inside visual studio but I didn't really want to have two different instances of visual studio up and running to do that so it works just fine editing and github okay so now let's talk about the concept of branches master is a branch and a branch is typically associated with a feature or a particular grouping of code the master branch is essentially the main version but then we can create additional branches so what I'm tasked with doing is adding a feature to this so what I want to do is I want to create a branch for that feature and then that gives me the ability to work in isolation on that code until I think it's ready to be merged back into master so to do that I'll go to the branches tab I'm going to right click on master and choose new local branch from and I'm going to give it a name and I'm going to call it new feature 1 and then create branch and then I'm going to remember that you can't have spaces so I'll just call this feature one so let's create a branch called feature one okay so now notice that it's highlighted now things I do I'm working on that branch so if I come into solution Explorer here and I add some code here's feature one and then I come back into program and I say code to call feature one right okay so now what I want to do is commit these have made changes added teacher 1 I MIT this committing it locally to the feature one branch and now if I push this I've pushed this branch up to github we come to github now notice that the master branch that files not in there the feature one files not in there the code to call feature ones not in there because it's not in the master branch it's in the feature one branch okay so again branches give you the ability to isolate the code you're working on and then when you're ready you would merge that into the master branch and the process of merging that is called a pull request which to me seems like an odd name since what I really want to do is push that code into the master branch but it's actually called creating a pull request so a pull request is a way of requesting it is a request that I merge the contents of my local branch into the master branch in our case or you could merge it into a different branch either way okay so now in Visual Studio I'm going to create a pull request I will create a new pull request I will call it feature one description added feature one and it is spectacular alright so let's create the full request you okay pull request has been created now I go out here to github and I look and pull requests and indeed there's a pull request called feature one I can ask for reviewers I can assign it to somebody bunch of other things we can do there's no problems here there are no conflicts so we now merge the pull request confirm the merge and now this has been merged into master so again if we're in master we come in here here's program dot CS and here's the code oops here's feature one CS and here's the code inside master to call it so the changes I made locally in that branch have been merged into the master branch in github but they have not been merged into the master branch yet in Visual Studio so what I now need to do is get my local master branch in sync so for example if I come here go to branches and go back to master I don't have that code and I don't have the file because it's only in my feature one branch so if I go back to feature one there's that code so locally feature one has the new code in github master has that code but locally master doesn't okay so what I need to do is sync the two of those okay all right so now is go into master to go to sink and I'm going to do a poll and now I'm going to pull I could do the Murr the fetch in the merge but because I just made the code and I know there's no reason not to I'll do the pull and now my master branch is in sync local master branch is in sync with github okay so that's branches that's pull requests now what happens if there's conflicts there could be conflicts okay so let's add some code to feature one so I want to say public in add and I say int X 1 equals 1 and int X 2 equals 2 and in some equals x 1 plus X 2 and then I will return some oh yeah that's beautiful okay so now let's push this a separate branch right now I will in the next demo this is all going to be done on master so I added the add method and I commit and then I push you and life is good so to github and we look in feature 1 there's the code I just wrote okay so now someone else in the team comes in here and looks at this and says hey wait a minute I thought we decided that we were going to use var whenever necessary whenever possible so changed into toolbar commits changes that code is now official if you will sitting up in github in the meantime I come in here and say ah I could do way better here so what I'm going to do is I'm going to refactor this a sin and then let's do this let's turn that and there we go perfect so now I say let's commit that refactored Adam let's stop worrying about typos commit push and failed what I going to output oh no sales with a fatal error now sometimes this fatal error happens because of the connectivity that's up there error I was expecting this is the error I was expecting so sometimes it fails with a fatal error and that just means it couldn't connect so try it again and we get the error we want isn't that odd we got an error getting the error back rejected updates updates were rejected because the remote contains work that you do not have locally there's a conflict it will try to do the push and to do the merging but if it can't we can't figure out how in this case is conflicting code then it fails so now the question is why why did it fail what can I do about it alright well let's see let's do a fetch let's get from github the code that's up there well it doesn't show me the problem because again the fetch just brings that code down and stores it somewhere so what we saw earlier as we go to the branches tab and do a merge so I'm going to merge from origin master into master and it tells me that it didn't work and then it shows me why oh this is the code I wrote this is the code somebody else wrote they're kind of conflicting with each other so I can click conflicts here double-click on this and I can compare the files aha so I have a choice I can take the source and the source is what's up in github I can keep the target which is what's local and in this case I'm going to say look my code I'm keeping the target keep the target commit the merge or conflict hit that sync Porsche you go to hub now I resolve the conflict by keeping my changes in completely overwriting the other person's changes so sometimes that's how you're going to be able to resolve a conflict one version of the code wins out over the other but sometimes that's not going to work so let's see an example of that I've now been tasked with creating a new feature feature - so we'll come into Visual Studio we can get rid of that let's go to branches right click on master new local branch from master and we're going to call it feature 1 oh no we're not we're gonna cost you too much better plan okay so now we've got feature two and then keep this nice and simple I'm going to add code to call feature to okay so I'm going to commit this added feature to minute locally and of course push it you so now what I've done is I've taken my local feature too and I've sent it up to github and there is now refresh the page for that drop down to refresh there we go there's the feature tube branch now in the mean time somebody else is added feature three and has added code to call a tier 3 3 and committed that to master so now what I want to do is a pull request I want to get my feature to branch into master so I come back into Visual Studio and I go to pull requests create new feature three added feature three and it is some of my best work ever bragging the pull request it's for requests and that it's going to work there we go latency into pull requests there's a pull request feature three conflicts that must be resolved lifting files program CS so you can open this and github desktop or command line instructions and I don't want to do any of those resolve conflicts I can see that there's a conflict I'm not going to resolve this year I want to resolve this in Visual Studio the feature 3 was already already had a pull request so the owner of the project will come to me and say Oh green fix the conflict before we do the pull request I say ok let's do that so again what do I want to do I want to see what the problem is so I will come into branches and in master I need to get the local version of Master down so I'm going to double click on that to make that the local one and then I'm going to do a pull right so what I want to do let's just make sure I get this correct okay I want to do a fetch I want to fetch on master bring it down okay now what I want to do over the branches tab urghhh from master into feature - because in order to send my feature to up it needs to have the changes that were in master okay so now going to merge from origin to do origin master which is the updated version of what was in github because remember let's back up a sec my local master did not have that change my local feature - is exactly what I wanted in github somebody made a change to master so what I need to do is take that change from github and get it into my local version of master so then I can then merge that into my feature to resolve the conflict and send it all back up okay so going to actually want to be in feature two here we're going to merge from origin master into feature two and now it tells me there's a conflict I go to conflicts I want to compare the files okay so I added code to call feature to somebody else added code to to call feature three I want both of this code okay so I can click compare files and then I will click on the merge and now notice is a little checkbox next to this code so I can here choose to keep both of the lines of code down into this which is what I'll then send back and the order I check confirms their controls the order that things get added so I actually want the codes call feature too before the codes call feature 3 all right then I accept the merge commit the merge and now result conflict peace is breaking out everywhere sink push okay so now the code in master alright let's see what we've done the code in master have my change code in feature two has both of our changes and this is what I now want to move into the master branch by the updated pull request was actually the same pull request but now there are no conflicts now I can merge this confirm the merge and now if we go back into code we go into master we go into program now here's the code to call 1 2 & 3 and then all I need to do once again is go back into visual studio and go to branches double click on master to make sure it's the branch that I'm now working on and then just do a pull now I am completely insane that is kind of the next level of working with gifts we've seen how we do commits and pushes and fetch merge pull we've seen how we deal with conflicts we've seen pull requests and branching actually covered quite a bit we've done this all inside Visual Studio with github now github is a place that you can store code and work with get there are others because remember kid is just plumbing so there could be any number of public websites or private websites that use git github is one of them again it's great for sharing code with people because you can make public repos and then people can easily view your code or download it you just want them to look at it or if you want to be collaborative they can of course clone the repository and then make changes to it via pull request so for example the dotnet core code or the entity framework core and a lot of our open source projects are running git and you can do a pull request and a pull request basically means that you bring you copy the code down if you will make a change to it and then ask permission to send it back and of course in our case those pull requests would would be evaluated by the product team to make sure that its code that we would want added back into the master branch any pull request has to be reviewed you would have the ability to decide you know how rigorous you are in that presumably you'd want only good code going in bit of a diversion so that's github another place to do this is visual studio team services visual studio team services not necessarily designed as a place that you share code with others more designed to be a place where a particular product team collaborates and works on code so they're more likely to be private repos and then there's another place another website called bitbucket we're not going to talk about that here but what I now want to do is show you how to do the exact same things we just did using visual studio team services so if you're only going to use github and you're not going to use VFDs and you made it this far you can stop now but if you're going to use VST s we're going to do the exact same demos we'll go through them a little bit more quickly because there's less explaining to do but we now want to see how this works with the SPS so I will go to my VST s site our o green dot visual studio comm which shows up as not authorized because I'm currently logged into this machine using my corporate account and I created that using I created my bftf site using my Microsoft account which is our green 2005 and msn.com so I sign out as ro green at microsoft.com sign it is our green 2005 and msn.com and now I can get to my visual studio team services sites I have a bunch of projects in here you can see that I've been practicing this so we're going to create some code let's create a new project let's call it get on toolbox just to [Music] identify it so the project name is get demos using VST s I can give it a subscription and notice I have two choices for version control can continue to use Team Foundation version control I can also use git which is now the default so I'm going to create this team project using git for version control is the equivalent step to creating the repository now VSPs also adds additional things like the ability to manage backlogs and queries with the Kanban board the ability to do the DevOps stuff with build and release continuous integration continuous deployment so VSDs offers out-of-the-box quite a bit more than github offers you can get these things with github but out-of-the-box vs TS all offers all of this stuff okay so now I can clone this inside visual studio from here or what I can do is pop over to visual studio go to team Explorer go to the Connexions manage connections right and refresh this list you go to connect to project Visual Studio goes out and we'll find the visual studio team services projects I am part of and it's in there similar what we call it but did we call it get demos using VSDs that's the one all right let's connect to that you okay we need to clone the repository again we're just using git so all the things we do are going to be the exact same things we just looked at so I'm going to put this in get repose own and now if we come out to get repose there's get demos using VST s and as you can see it is in fact a git repo okay so now we can create a new project all right so let's go here the homepage team Explorer there we are now interestingly this doesn't show all the same choices that we've seen before pull requests and other things aren't there if I go to the home page I'm sorry if I go to connections and I double click on this get demos using VSPs now it looks like more now it looks more like what we're familiar with ok so now I'm going to create a new solution again it's going to be a console app in the same places we did before okay changes commit raided project again going to go through these very quickly anything that's the same as we just saw I'm going to move through fairly quickly sink push you okay now this code is sitting out in bsts if I go to code and I look at files there it is console app one Dada program dot C s okay I can look at history of the project I can come back in to contents and I can go into program CS and I can edit this added in the SDS committed okay back in visual studio do a poll I could do the fetch and the merge I'm just going to do a pull there we go and of course I can make changes in here code added in vs right change added code commit go to sync to a push okay come back to the STS refreshed page there we go okay let's work with a branch so let's come into Visual Studio okay and into the team Explorer go to branches right click on master new local branch from call it feature one print branch okay now we're working in feature one so I add a class put it at a class right click add class thank you very much feature one okay and then in program code to call feature one all right so now kids it made added feature one will commit which commits again to the branch sync to a push I'm not sending my feature one branch up to the STS so I can come out here and there's feature one which contains what I just wrote and of course master does not yet because I need to do a pull request come into Visual Studio the home page here create a pull request you are not connected to a remote repository actually I am do a pull request which takes me to visual studio so this is a little different the linking the connection between visual studio and VSDs works a little bit differently here so again we're using the same plumbing the same get plumbing underneath the hood but the UI will be a little bit different so when we were using github you created the pull request inside Visual Studio when you're using VSDs you create the pull request takes you to VST s you'll see a couple other examples where the UI differs coming up okay so new pull request added feature one description added feature one you can still create you still have reviewers create the pull request okay so now I can approve this explicitly from here or wait for the author approving suggestions reject these are all things that you can do in github so now we will complete this here's another difference after you do a pull request you can delete the branch it's your choice whether you want to or whether you don't want to when you're working with Visual Studio and github you automatically do not delete the branch you have to go do it if you wanted it in the SPS by default you do delete the branch so we'll just leave this selected we'll complete the merge this work yes it worked okay excellent it work two minutes ago all right so apparently apparently it didn't refresh the page automatically cool all right so now go back into visual studio and I move back over to master so I've taken the feature one code merged it into master up in BSP now I'm just going to do a pull and get that down into V s so now V s and V STS are in sync okay what happens if there's conflicts so let's go into feature one and let's add that's code and I'm going to see if I can very quickly copy that I don't really feel like typing it all over again it was in feature one I like to use visual studio code to just look at individual files because it starts up faster than visual studio okay so this is the old version of this so int X 1 X into X 1 equals 1 [Music] into x2 which I that was the new version of that but it's still hopefully a little bit less typing and then return it some all right so there's my code to commit added add method myth sink after Bush okay cool now we come to the SPS we go to code and in the master branch we come down and somebody's looking at this and says hey I thought we decided that we were going to use var whenever possible okay so I'll commit this and is changed in two var committed right so now I'm back in Visual Studio unbeknownst to me change at the same time that I was refactoring this and I now say let's commit this refactored ad method I commit I push once again the push fails push should out for the exact same reason the exact same error message comes back okay so what do I do I go here oops I could have done the fetch from there I do the fetch right and then and I want to do the merge so I go back to branches and you wanna remind master I'm still in master right yeah okay so now I do a merge from origin master to master which fails shows me why I go to conflicts do the merge which shows the files I say up keep the target which is my version commit the merge solved conflict send it up or comitted excuse me now do the push to send it back up and I come up to here do a refresh my version goes up the last demo we did was we created a poll recruited a branch and then the poll request failed due to a conflict so let's see that okay we go to branches right click on master create a new local branch called feature to okay and then what did in program one code was we said code to call feature too we commit that added feature to and we pushed that branch you branch up into the STS while we were doing that in the main branch somebody made what will wind up being a conflicting change to call feature three you commit okay so now I want to create a pull request to get my feature to into the master branch and create a pull request feature to add feature to and it is fantastic unlike my typing abilities okay create that and no not going to work conflict prevents automatic merging okay so I can abandon this and asked me to go fix this so I come back to here what do I need to do again I need to the conflict is in the master branch in VSDs that's origin master so I need to get what's in origin master into local master so that I can then merge it into local feature - okay so we go to branches we go to master we need to go to sink first and get a fetch fetch into master then go to branches and then do a merge from origin/master into so actually we wanted to merge that into feature two excuse me origin master into feature to do the merge which fails because there's conflicting code conflict put conflict click merge I want this code I want this code I accept the merge I commit the merge I've resolved the conflict myth Porsche up into the STS pop over to BSP reactivate the poll request which can now be completed there we go and then finally which took files just to make sure not that you doubted for even half a second that this didn't work perfectly there we go and finally come back individual studio and make sure that our master is in sync so we changed the master and we do a pull good to go so that's it there you have it that in a nutshell an hour long nutshell of course the basics of how you use git we looked at the basic plumbing of get what does it do we looked at how you work with Visual Studio and github using git we looked at how you use visual studio with visual studio team services using git and we saw that it's the exact same plumbing underneath but the UI can differ as it might if you were to go use something like fit bucket so I hope that helps demystify gift for you I hope you enjoyed that and we will see you next time on visual studio toolbox [Music]
Info
Channel: Microsoft Visual Studio
Views: 130,906
Rating: undefined out of 5
Keywords:
Id: c3482qAzZLQ
Channel Id: undefined
Length: 70min 25sec (4225 seconds)
Published: Wed Aug 02 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.