Transcript
  • Servers and Tools

Setting up Remote Git

From the class:  Git Deploy

I'd like to be able to add that deployment server as a remote to my local Git repository. So I type git remote-v I want to show up in that list. And that way, I can type git push, and then name it deploy, and the whatever I want to push up to it, say the master. And that becomes a really slick way to get this source code up to the server.

To do that, what we need to do is just SSH into the deploy server, and we need to set up that repository under apps/boom. We need to create a Git repository here. To make this a little bit simpler, I'm just going to go ahead and delete the current folder that we created last time, and we'll recreate it. So we're just starting from scratch. And make sure that it has the right permissions and change into it.

To create a Git repository inside of this folder, we're going to do it the same way we would with any other projects. I'll say git [? inut ?] except I'm going to provide a couple of options. The first is called shared. That's going to allow multiple different users that are in the same group to push up to this repository, and then I'll press Enter.

Next up, I need to configure a couple of options. So the first one I'll configure would git config. We're going to say that this is a Boolean option, and it's for the receive section. I'll show it to you in the actual config file in a second. And we're going to set that denynonfastfowards option to false.

If you're wondering what that option is when we push up to this remote server and the git server receives, receives what we upload, normally, if the thing that's being pushed is not just a regular fast forward merge, then the push will be rejected. And we're saying here that we don't want to be rejected, go ahead and accept anything. There is one more option we need to provide. So I'm going to say git config, again. And this time it'll be for the denyCurrentBranch option. And we're just going to ignore that.

If you want to learn more about these different options that go into that go into git, you can check out the manual pages that by using man git config. That will give you all the different configuration options for git. And you can use the forward slash to search through this.

For instance, if we want to find the option that we just used, I can type denyCurrentBranch. And that will find the configuration description. And here it's telling us that, this option, if it's set to a true or refuse, it will deny any push up to this remote repository if it's not set to the currently checked out branch. And so we just set that to ignore, because we don't care about that, and press Q to get out of this.

To double check that we have the right config, you can just open it up and VM, so .gitconfig. And notice that it created a section here called receive. And those two options that we added with the get config command line tool were created right here.

Up top, I'm going to keep us logged into the deploy server, and down below all have us on the current project folder. So this is our project. And let's go ahead and add this deploy server as a remote to this local Git repository. I'll use the git remote add command, and I'll call this deploy. You could call it production or staging, whatever you think makes sense. But since this is a general deployment class, I'm just going to call it deploy.

And then we need to provide it an address. Now the trick here is that we can use the host names that come from our SSH config. So I can call this deploy. And then I just need to give it the path to the Git repository. In this case, it's going to be apps/Boom/Current.

So the first part here will be the host that we defined in our SSH config, and then there'll be a colon. And everything after the colon is going to be the location where it should go find the Git repository. And since we have this git directory in the current folder, that's the one that we want to send this to. I'll press Enter.

And now if you type git remote-v, you should see that we have a deploy remote that's been added. And now the moment of truth, I should be able to say git push deploy master, and it should deploy our master branch up to the remote. And we get a successful message back here. It says it deployed to this location, and a new branch was created on a remote, as we would expect, since we started from scratch.

Up top, if I refresh this, there's no files or folders yet, even though we did push up to the git database, and that's because the push itself doesn't check out the latest stuff into the working tree, into this working directory. We're going to have to do that by hand. We're later going to automate it, but for now I'm just going to do it by hand. And I'm going to say git reset and use the hard option.

And when I do that, now the latest has been checked out into a repository. So we have the latest code on GitHub or on git. And by hand, I can say pseudo system control restart boom. And so every time I push up to the server, I could just manually restart it, and we should have the latest stuff. So at the very least, now, we've been able to get our code up to the deploy server simply by using a git push command, instead of by copying it using regular SSH. Next up, it would be a little bit easier if this process could be automated, and we could restart the application server automatically.