Host Git Server on RaspberryPi! | 4K TUTORIAL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right what's up guys today we're going to be talking about how to host your own git server using a raspberry pi this will allow you to one keep control of your own code meaning it's all yours and two means you will never have any size constraints as long as you've got the hard drive space on your raspberry pi so if you don't know a lot about git git is an awesome way to manage code and other projects basically what it allows you to do is commit pieces of code and all group them together so that means if you have a team of people working on code they can all be working on it together and then merge those in slowly over time without breaking anything another thing it's great for is having revision history so you can go back to old revisions of code you've written and say oh this is where that broke i'm going to go back and see what code i had there and pull it into the future it's a really great way of managing everything though at first it is a little bit tough to understand this also can be used for personal projects even without a team of developers i personally use git to version control all of my code whenever i'm writing it that way i can always go back and see old versions of the code and be able to get the most recent version on all my devices ends up being really easy and hosting at home makes it quick and easy to set up and i know that that code that i write nobody else is going to have access to unless i give it to them so i'm going to be doing this tutorial on a raspberry pi 4 and using it on my mac though git works with linux mac and pc and so you should be able to work with it from wherever using your favorite git client but for setting this up we're going to go over how to do it purely command line driven and i think that really gives you a good way of setting things up another thing to note if you want to use this outside of your own network you can do that but do not just port forward the ssh port from your router to your raspberry pi that is an awful idea and is a huge security vulnerability instead what you're really going to want to do is set up a vpn server on your raspberry pi i would recommend setting up a wireguard server it's incredibly easy to set up and i've got a tutorial for how to do it in the description below then from there you can always just vpn back into your home network and be able to access your code from there and even better you can also access all the other assets on your network as well so if you have something like a nas you can access all the files that are stored on there over this vpn all right so now what do you need to get this tutorial started well you need a fully functioning raspberry pi that you can ssh into and you're also going to want the same ip address given to that raspberry pi all the time it'll just make your life a lot easier and so you can either hand that out from your router or you can set up a static ip address and if you don't know how to do that i've got tutorials on how to do both those things and i'll put those in the description below all right and so now once you've done all that let's go ahead and log into your raspberry pi and so this is a fresh install of raspbian so the first thing we're going to want to do is do a pseudo app update to update our packages all right so what this does is just make sure we have the most up-to-date version of where all the packages are and so now we're going to use apt-get to install get so we're just going to do sudo apt install get just say yes all right and so now that that's installed i'll go ahead and clear and give us some space all right and so what you're actually going to want to do for best practice if this is a serious code base is you're really going to want to install it not on the raspberry pi sd card but instead grab an external hard drive or even a flash drive and have the repository live on there the reason for this is simple sd cards break they are much more likely to break than flash drives and so you don't want your raspberry pi's sd card to break and all of a sudden you've lost your entire repository you would still have all of the code because it's kept on everyone's machines but you would not have that history and i would also recommend backing it up especially if it's a more serious project now if your sd card were to fail but you had the repository on a flash drive plugged in then you would be able to grab that plug it into a new raspberry pi or a new installation on the same raspberry pi and be able to get it up and working almost immediately again and so that's what i would really recommend doing it's just a much safer practice and i've also got a tutorial in the description for how to set up a flash drive on a raspberry pi and so act just like any other flash drive on a computer and will automatically mount at boot up so it's always there but for this specific tutorial i'm going to be breaking that rule and just doing it directly on the sd card itself and so the first thing we're going to want to do is actually make a folder for the repos at the root directory so we're going to do a pseudo mkdir repo and so now if we cd into the root level and do an ls we'll see right here that we've created this repo folder so let's go ahead and cd into it all right and so as you can see there's nothing in the file yet so now let's make our first project and so what i would recommend doing for every single code project you've got create a different directory in here and so what we're going to do here is actually make a directory for our code base so we're going to do it mkdir and this project is going to be about cat so we're going to call it cats ah sorry sudo mkdir so now we've got this repository called cat in there so let's cd into it so now we're in the repository cats and it's empty but that is good so the first thing we're going to want to do is now tell git that this is a repository for git and so what we're going to do is we're going to do git init bear period ah sorry sudo so now we have an empty repository in repo cats so if you're doing ls we will see that there's a bunch of get stuff here and you're not going to want to be editing this at all another thing you are going to want to do however is go back to that root level repository so we're going to do cd to repo and we're going to want to make sure that everybody has read write access to this folder because that way their git will be able to make the changes so by doing that we're going to do a sudo chmod 777 and then period so that will recursively change the modification rights for everybody and so now everybody should have the ability to read write and execute code within this directory so one other thing you're really going to want to make sure to do is this is your bare bones repository that means you should not be editing any code within there or ever touching it you should only ever be interfacing it within git so it should also be the one that is stored on the external drive just in case your sd card failed so now let's also just see what's going on with cats so we're going to go into that cats file and we're going to do a gift and so you'll see right here that there are no commits yet to it and so now let's go ahead and be able to do something so right now remember we are in this slash repo cats right so let's exit out and go back to our home computer i just typed in exit which exited from the ssh shell back to my home computer so i'm just going to clear it all right so now i'm on my local machine and i've already got get installed you're going to have to install git on whatever machine you've got so go ahead and install git and for mac what we're going to do is go into whatever folder we'd like to use for code so i've already got one here which is code and so within here i've got a bunch of different code projects right and so this is the folder that i use to store all my different code repositories as i'm working on them and so we're going to add in that cats one so we're going to do it just say get clone your pi username the ip address of your pi colon the path to that repository so remember for me that was slash repo slash cats and you're going to see here we have to enter a password so warning you appear to have cloned an empty repository but we know that so now let's go into that cats and there's nothing in there but let's just add something we'll do a touch test so now we have a new file so forget we're going to do a git add period for all and so now we're going to do a git commit so i'm skipping over a lot of the core functionality of git here there's a ton of tutorials online but i'm just going through the steps right now so now we're committing and so i'm just going to edit this just always call it first commit all right and so now we've just committed those changes that we made adding that file to our own revision however it is not on the server yet to get it on the server now we're going to have to get it do it get push it's going to ask for that password again and just like that we have now successfully gone and updated the master branch on that initial repository and so that means it's working we can continuously do our edits here and keep using git as you normally would so that's all great right however there are two things we're going to want to do first off we do not want to have to type in our password every single time all right so to keep from having to type in our password every single time we're going to set up what's called ssh keys and i've actually already got a tutorial on how to set up ssh keys on a raspberry pi and so i'll link that in the description but it's very easy if you've already got them set up on your computer so i'm just going to do it ssh copy id and give the login all right and so i just added those ssh keys so now let's go ahead and just do a quick nano and edit that one file so we just did an edit to that so we're going to do another git add and git commit so we have now committed it and now let's do a git push and see that time i did the push without having to type in a password because it had those ssh keys on there so what i would do is give all of your friends accounts on that raspberry pi and have them all set up their own ssh keys that way they'll all be able to send code in and have it work perfectly without having to type in a password every single time all right there still is one other thing doing this from command line gets very old very quickly and so nobody really does that because it's so clunky instead they use gooeys and so my favorite text editor which is adam actually has built-in git support so adam is actually built by github and so we're going to go in and open up close out on these and we're going to open up a new project and we're going to open up that cats script and this is that directory and so all i've done here is i opened up the cats get directory as a project in atom and so now let's say i'm writing some code and so now i want to update those to the server so it's got this great git over here so now that i've saved it we're going to see right here there are un stage changes and so to stage them all you have to do is double click on them and it'll show you what the changes are alright and so now we go okay yeah i like these changes this is how we've changed it up and so we're going to want to commit it and we just type our commit message right here and we can commit the master so now we can also see right here that there is this push so now all we got to do is click push and without having to type our password or anything it is now on that git server and so all of your friends will be able to merge in these code branches and atom is a great way of managing a get server another great one is fork fork is much better for allowing you to visualize different repositories so i'll go ahead and open up a new one and open up that cats again and so right here a fork is going to show us these are the different commits this is where the master is master is local to our computer and this is where the origin is origin is the one on the server that raspberry pi that we set up and so it is great for allowing you to see things you can see all the commits you can go through the two different time histories and you can also do diffs then you can also do pulls fetches and commits and so you can use something like fork to manage and see all the different repositories but i'm not going to go into the really intricate workings of git because there's tons of information already online and quite frankly i'm not the person to give those tutorials however this is how you can super easily set up a git server on your raspberry pi and so that you and your friends can have your own dedicated git server for version and code or even storing massive files this works say you're editing a bunch of different images and you want people's opinions you can go back and look at old revisions and be able to say oh wait maybe we should go back to that git is a really great way of managing everything and i would highly recommend to use some kind of version management system for any code you're writing even if it's just for yourself all right well that's all i've got for this tutorial i hope it was helpful have a good one bye [Music] you
Info
Channel: SpaceRex
Views: 14,044
Rating: undefined out of 5
Keywords: RaspberryPi git Server, self Host git project RaspberryPi, version control code
Id: jMqDJ0mcIvc
Channel Id: undefined
Length: 16min 21sec (981 seconds)
Published: Tue Aug 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.