Git Good with Git | Xcode 12 | Swift 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody and welcome back to the channel in today's video i'm going to show you how you can get good with git specifically using xcode as your main tool for doing so so for those who don't know git is a way that you can manage your own projects and is a source control tool so if you're working on a big team if people are making a lot of changes you want a way to make sure that all those changes actually make it into your code base but if you're just a solo developer you can use get to branch and do all these kind of different changes test some things out without having to worry that you're going to mess something up completely and not be able to get back to where your project was working so first i want to show you how you can actually get a repository on your computer because a lot of times that's going to be the case you know if you join a team they already have their own git repository working they already have their code base you need to get it onto your local computer so that you can start making changes so in this example i'm just on github i'm on my own profile and this is a project that i created following apple's tutorials for how to learn swift ui so in order to get the code onto my computer i'll simply go to this green code button click and then you'll see this option to clone now you could just download a zip but what we're going to use is this clone option so that as we make changes make updates we can actually push those changes to this remote here on github so go ahead and click this little button that'll copy it to our clipboard and now i want you to open an application called terminal so if you hit command spacebar you'll get your spotlight search on your computer and go just type in term and you'll get terminal so i'll make this a little bigger so it's easier to see but for those who haven't used terminal i'm not the biggest fan i know there's huge debates about this but what we're going to do we're going to find a location where we want to add our repository clone it in and then everything else is going to be in github this will be the only terminal stuff i promise so to navigate your computer in the terminal you use something called cd the command cd that's change directory short for that and then i'm just going to go to the desktop so now i'm on the desktop if i hit ls which basically just lists out everything in that directory you can see i have a whole bunch of stuff but the command that i want to use is git clone and then i'm going to paste in the link that i had before so the landmarks.get from my profile you can see cloning into landmarks all that's been done if we do ls again you can now see that landmarks has been added so if i go over to a finder window that i have open you can see landmarks and here's our xcode project so i'll go ahead and open this up and now you can see we are on or we are in xcode so this is xcode 12. i really wanted to show this demo using xcode13 but i found there's still a number of issues uh when trying to work with it so thought might be better just to be safe and use these stable versions so you can see this is the project that i have if i run it real quick for those who haven't built out this project before that apple has on their website you can kind of get an idea of what the app does what it looks like some of the functionality so brings up here in the simulator iphone 12 mini and once this loads you'll see a whole bunch of national parks lakes there's like this featured section you can scroll through and when you click in you actually get a detail view so you can see a map a name some more information from here and this is actually coming from a local json file so it's like this landmark as i knock everything and send the camera flying uh there's this landmark data json so this is actually pulling information from there and we're just gonna make a whole bunch of changes and i can show you how you can use get to your advantage to not really mess anything up so the first thing i want to show you on the second tab this is your source control tab source control navigator excuse me so if you click in you can see we have these sections for branches tags remote stash changes so if i navigate down here you can see branches right now we just have one it's main tags no tags remotes this is origin and that is the remote that's actually on github so if i right click this and i say view on github you can actually see that it pulls up the repository on github so that's the way you know that things are actually being hosted online so we come back to xcode stash changes no stash changes so i'm not going to see anything there but what i want to show you if you're on branches and you see main here are all of the commits that i've made as i was going through this project and had it on github so if we want to make some changes let's go ahead and right click and we can hit branch from main and i'll just call this something basic made changes if you're working on a team or even if you're by yourself give your branches descriptive names so you can actually understand what you're doing it's very helpful it makes it easier for your team to understand and it makes it easier for you to understand if you come back to your project like two or three weeks later and don't remember anything you did so now i have the made changes branch i'll go back in here and i'll pull up the landmark info again so if we were looking at the not that if we were looking at the simulator and we actually had uh what was it it was this turtle rock so joshua tree national park if we try and find that so turtle rock joshua tree national park this is the json for that so we can see all this description let's just go ahead and pretty much get rid of all of this i can show you when you delete and then i'll save anytime you make a change when a project is under version control or using git xcode has this helpful little tool that it shows you in line changes that were actually made so if we click on this you can see show change discard change so if we show the change you can now see xcode brings up everything that you changed so if we hide this again and we'll rerun the project so this build succeeded it'll launch now we can come back down here once this is clickable so go back come back to turtle rock now you can see we got rid of the description so that's gone now another thing i wanted to change is i think this border on the image could be a lot bigger and i think we could have a bigger shadow let's just make this as obnoxious looking as possible so if we go on to our circle image so it's in the helpers group if you're making these changes with me but even if you're not this applies to any and all projects that you're working on with xcode the version control system is not going to care what the project is so kind of going for the concepts uh to help you understand how you can actually use xcode to your advantage when working with git rather than having to use an external tool or god forbid the terminal so this will start loading up and you can see here is the current implementation of the circle image pretty small but i'm just going to make this obnoxiously large so we'll make it 40 and this will be 10 yeah make it 20. so now we have this really big ring really big shadow and again we see what are the changes that were actually made and if you quickly just want to discard all your changes you can just hit that and it'll revert back to what it was but see how i don't want that i do actually want some changes to be made now you can see made those changes and now i'll run it again and we'll see what all of our circle images are going to look like when we actually run it in a real project so i can click on any of these i'll do the silver and samurai creek and there we go big and obnoxious just like i wanted so if we go back now i've made a number of changes that i like i'm happy with you see these little m's so these indicate that something's been modified and we're going to push those changes up to github so the way we can do that actually commit the changes we've made is here in this source control tab you have the options to commit push pull we'll do those here in a minute but first i want to show you commit so you can see there is the shortcut if you don't feel like using the menu every time but if you hit commit you'll now get this section here on the left that shows you either in the hierarchical format or in a flat format everything that got changed so if we stick with hierarchy doesn't really matter whatever works for you you can actually see the history of your files so what was the change here's what it was before and here's what it currently is so i deleted everything same thing if we look on circle image it used to have the overlay with a line width 4 and then had the radius 7 i updated it to 40 and 20. so i'm cool with that made some changes to descriptions and circle image so those are the changes i want to make those things i want to commit and if you're ready to actually push this up to github you can go ahead and hit this little check box in the bottom so push to remote and then has the remote that you want to push to on the front so that's origin as well as a branch where it's going to actually send it so here it's made changes and you can see there's this little like parenthesis cr so what that means is it's actually going to create the branch because remember i created that locally on my computer github doesn't know about that yet so if we go ahead and push it up commit two files and push so this will take a minute to load and then it will actually push up our changes if we go into our source control navigator again you see we have made changes and if we right click now you can actually view on github so if i view on github we can now see that i am in the made changes branch as opposed to the main branch and you're also getting this little pop-up here that is showing that made changes had recent pushes less than a minute ago and if you're working on a team this is typically how you will actually request that your changes make it into the main code base so to show you a quick example of that you can do a compare and pull request so when you open a pull request you just give a description things you've done some teams will have templates of things they want you to fill out describing your changes but then you just go ahead once you finish filling that out create pull request and now on your repository it'll show all of the open pull requests so if we go back one level you'll have a bunch of pull requests that have been created a bunch that have been closed but if you click into here you can actually see all the details for it so made some changes to description circle image that was just the commit message i made you can make updates to this and then you'll see every commit that is in this pull request any kind of checks that have been done teams will have custom checks to make sure you're not merging anything and that's broken or not ready to be added yet and then finally files changed so you actually get a good summary of everything on a file level that's been updated in this project so you can see for me i updated description to not have anything just on that one section of json that one section of json that related to the joshua tree park as well as made updates to the line width and the radius on the circle image so if you're actually ready to merge those things in you can always do merge pull request and then this code will be added to main but what i want to show you back on xcode every change that we've made remember was done in this made changes branch so right now if we resume this you'll see we currently have our really obnoxious border with the big shadow but if we simply right click on main and we do check out you'll see this pop-up asking do you want to check out main so it's basically a warning it's just saying all files in the current working copy are going to switch over to the main branch or whatever branch you're switching to so i want to go ahead and do that i'll hit checkout and now if we resume this again you might have already caught it down here at the bottom these numbers updated right so as you can see all the changes that we made on that one branch aren't affecting the main branch so this is great when you're working as a team so any kind of changes that you do aren't going to affect what someone else is doing and vice versa and if you're just doing this as a solo developer it can be really helpful because if there are a bunch of changes that you want to make but you're not really sure how to do it or you're not sure if things are going to break you can simply add a new branch and then do all the experimentation you want and if you end up breaking your project doesn't really matter just switch back to the branch you don't have to worry about trying to do a whole bunch of undos and redos so it's a great way to actually manage your projects and the last thing i want to show if you are working as a solo dev if you haven't or you're starting a brand new project even if it's on team if you want to create a brand new project how can you actually get xcode to use git right from the beginning so if we do new project it doesn't really matter what it is get test again doesn't matter hit next there is this great little source control toggle here that xcode gives you automatically when you're creating brand new projects so simply click create git repository on my mac and then it will automatically do that for you so hit create get test if i just want to do real quick show you that i'm not lying that it will actually use git for you if i just delete this there you go we can see we got our little blue bar show changes shows the m and you can follow a similar process so if you've made all these changes locally and you actually want to get this on github so rather than pulling things down from your remote you can actually add this to an online remote so you can come in here get test go on to remotes you click you see oh there's nothing there okay that's fine so now we can right click and you have this option of new git test remote so when you click that you can see i already have my account set up to where it's my github i'm the owner i can give it a name can give a description if i want but i don't really care so now i can create and this will push everything up to github and now you can see this little origin has popped up and if i right click view on github this is now my repository on github so the last thing i want to show is when changes are made that you didn't do how can you actually get those into your project so we're going to use the one that i just created we're just going to add a readme so add a readme and we can just say this is a simple test to show how to pull from github so there we go commit the new file and now you can see we have get test and it's the added readme and we want to make sure we actually get that change brought down locally so first what i want to do is in finder we have our get test you can see there isn't any readme file right we have git test we have the project so that's all great but now we actually want to get the readme into the project so if we go back to xcode save first thing i want to do before we pull anything i'm going to commit and push this change so we have our constant so updated hello text and then we'll push commit one file and push and now what we can do we can use our source control and pull down the changes to actually get the readme so if we pull and now if we come back to the finder you can see now we have our readme file showing up so be sure when you're working on projects when changes are made you get notified just pull down the latest changes and then you'll be working from the most up-to-date copy so that you don't run into any kind of conflicts later you know kind of pushing and pulling and you kind of working on an outdated repo well that does it everybody hopefully this video is helpful kind of give you an introduction to how you can use git with xcode i highly recommend even if you're just a solo developer using git using branches it's a great way for you to organize your projects and test out features that you aren't really sure might work and it's absolutely essential to know when you're working on a team so that you actually understand how you can manage your code actually getting added to the real repository and not really messing with anyone else so if you enjoyed the video please be sure to leave it a like and consider subscribing i appreciate it everyone thank you so much and i'll catch you in the next one [Music]
Info
Channel: John Kouris
Views: 175
Rating: undefined out of 5
Keywords: Git, Swift, Swift5.5, iOS14, SwiftUI2.0, Xcode12, Programming, Walkthrough
Id: SK5nVxT2Yxc
Channel Id: undefined
Length: 18min 51sec (1131 seconds)
Published: Wed Jul 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.