Connecting a Rails Project to a Remote GitHub Repository

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there we're gonna do a quick video today which is going to cover creating a rails application which is then going to use git version control and we're going to synchronize our local repository with a remote repository on github and so I've got a new rails application which is building behind the scenes right now and while that is happening I'm going to go over to my browser and it all begins if we want to synchronize a local repository to a remote this remote can be on something like github it could be up on something like git lab or bitbucket it doesn't really matter where it is the sort of overall pattern of long interview it's gonna be very similar but we need to create the the remote repository via the web here so I'm logged into my get up account I have a separate account specifically for my repositories that have to do with my work at the college and then up at the top here I'm gonna click this button and one of them is for new repository that's what I'm gonna click I'm gonna specify that the owner is going to be my stun I our RC account and then I'm just gonna call this remote source control demo so looking up local rails get you oh that day yeah um remote we're gonna keep this public and one thing we don't want to do is we don't want to initialize this repository with anything in it because we're going to almost immediately connect it to a local repository and then we're gonna pull our push all of our local files that we commit over into this remote repository so we don't actually want to start with anything in this remote repository because then we might deal with some well then we would deal with some merge conflicts because there would be data in this repo that would not match the the local repository so I'm not gonna click this button I'm not going to add anything else I'm just going to create repository I'm now at the URL for this new repository so this is where it what URL you would visit when you want to see this repo up on github I could add teams and collaborators at this point down below here there are some instructions for what we would need to do to hook this up to a local repository there's one for if you need to create a whole new repository from the command line or if you need to push an existing repository from the command line this is the one we're going to be doing specifically because when you start up a rails project it by default one of the conventions of rails by default is that the project is going to be already initialized as a git repository it will already have that hidden dot git folder we'll just have to make an initial commit into that repository and then we can run these two lines of code that are provided so we can go over here and see how things are going so we're almost at the point where the project is up and ready we're just at the yarn install step so the other thing I'm going to talk about here is that we have a choice to make which is the difference between making this what we're doing is we're adding a remote so you can see this command here get remote add and we're adding a remote and we're giving it a name and the the standard name for your remote is origin so this is what is our github repo is going to be known as it's gonna be known as origin but that you know you could put a different name there the name itself is not important so we're adding a remote we're giving it a name and then we're linking it up to either an HTTP URL or if I click this button up top here an SSH with a username and a path now the difference between the two is if you make an HTTP remote when you push to it you're going to be asked for your github username and password if you do as this age well then you will have needed to set up a public/private key for authentication and so I'm not going to cover that in this particular video but you can learn more of that if you go to your settings and then specifically you go to the section for SSH and GPG keys this is where you add keys and it you'll find a link there which will provide you with some steps for how to actually go about creating a public private key on your local machine and this will be different depending on if you're creating it in Windows or if you're creating it in Linux for the wsl and so I'm not going to cover that but if you if you want to go password list like if you don't want to have to always enter your user name and password then it would be better to put in some time and to set up a public private key you basically keep your private key private it stays on your own machine the public key you upload that to github and you you flag it as like this is my public key and then when you set up a remote that is an SSH remote that those public private keys will be used behind the scenes to authenticate to it you won't have to provide a username and password for simplicity's sake though you could just go with HTTPS I've already set up my public private key so I can use SSH over here our rails project is done I can navigate to it I had originally built it just by saying new rails and then the name of the project so I'm going to navigate to that folder and then I'm going to open that folder here which is in my Mount C full-stack and it's inside of the rails and then it's called remote source control okay we're not actually going to add anything to this rails app we're not going to do anything really with it at all the whole point here is just to set up github if we look there is the version control section or source control section of vs code it picks up all the changes so I could commit I could make my first commit in one of two ways I could at the command line do a git add dot to add everything and they didn't do a git commit - em and call it like the initial commit and then the other way of going about this would be to just do it from within the S code I need to say initial Ament at this point I could sort of cherry-pick which files that I want to commit by clicking this plus button I want them all so I'm gonna hit control enter and B is code will just ask me would you like to automatically stage meaning add all these changes and then commit them directly and I'll say yes so I've made my first command if I do a git log you can see it in there I'm on my master branch I I've set my terminal up that it displays that you could also check that out by saying get branch and it'll tell you that you're on your master branch the reason we want to know that is when you are pushing to a remote you need to know which branch you want to push and currently we only have one branch and it's called the master now I want to add this remote so I'm gonna grab this whole line here copy and paste it in again you're probably gonna go with the option of using HTTP but you could use the SSH option if you set up your public private keys add that if you ever don't know if your repo has a remote attached to it or not you can always type get mine is a V for verbose and it'll tell you and here it shows that we have a remote called origin that's set up verbal fetching and pushing and there it is and now I all I need to do is get push origin master and I can add an extra flag to that so that it will always remember the name of the remote and the name of the branch so if I put a minus u on there then next time I just need to hit get push and it will use the previous remote and the previous branch for me so this is asking get to push a master branch up to origin which is this github that we've defined I'm gonna hit enter there it asked me for the past race for my private key I type that in if you used HTTP that's the point at which you would be asked for your github username and password looks like everything was successful branch master set up the track remote master from origin we go back over here and reload this page there we are one commit it's the initial commit there's my entire rails project and down below we're displaying the the default readme file that is in the repo so that's it that's all I wanted to show you after this point you can continue committing you can commit as many times as you want without having to push it up so one thing to know is that when you do a new commit that will not be immediately recognized remotely so you can commit locally as many times as you want and then the next time you want all of those commits one or more of them to be pushed up to your remote you just have to hit or type in get push and it will push those remotely and that way you could do a whole bunch of work even not connected to the Internet continuing to commit locally and then when you're ready you can push up a whole series of commits and that's sort of the idea of this this distributed version control that get allows us to do all right thank you very much for listening to me talk today about hooking up a rails repository with a github remote
Info
Channel: Kyle Geske
Views: 186
Rating: undefined out of 5
Keywords: Rails, Ruby on Rails, Git, GitHub, Source Control, Version Control
Id: ZmA0VE2Lj2U
Channel Id: undefined
Length: 10min 56sec (656 seconds)
Published: Fri Feb 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.