Posted by & filed under Web Development.

Those who have used Github know how nice it is to be able to “git push” your work to the cloud, how nice it is to have this repository function as a backup of your work, and how nice it is to be able to so easily “git pull” this project down to another machine. The following tutorial details how you can setup your own private Github repository, minus the web interface and all of the features that go along with this (e.g. comments, pull requests, etc.). This approach is great for when you might want to store some sensitive and/or proprietary information in your project (other than database passwords and content which can be easily added to your .gitignore file), and you don’t wish to purchase a private Github repository.

Those who have used Github know how nice it is to be able to “git push” your work to the cloud, how nice it is to have this repository function as a backup of your work, and how nice it is to be able to so easily “git pull” this project down to another machine. The following tutorial details how you can setup your own private Github repository, minus the web interface and all of the features that go along with this (e.g. comments, pull requests, etc.). This approach is great for when you might want to store some sensitive and/or proprietary information in your project (other than database passwords and content which can be easily added to your .gitignore file), and you don’t wish to purchase a private Github repository.

On your server:

  1. Make a new directory where you want your project’s copy to live
  2. In this directory run git init --bare. You’ll of course need Git installed on this machine

If your changes are already being tracked Git:

  1. See what remote sources you have defined via git remote
  2. If you have an origin defined, change it to the directory of your new repository you have created in the above steps by editing your .git/config file. If the repository resides on another machine accessible via SSH you can define the origin as ssh://[hostname]/path/to/repository
  3. If the origin is not defined define it via git remote add origin [path or URL to repository]

If they aren’t:

In your main project directory do a:

  1. git init
  2. git add *
  3. be sure to also git add your .htaccess or .gitignore files if you have them
  4. git commit -am "initial commit of my project"  (your comment can obviously be whatever you like)
  5. git remote add origin [path or URL to repository]

Push your project files to the server for the first time

git push -u origin master

You can then clone your server’s repository via a git clone to download this project to other machines. You can create a great workflow using the above instructions that will allow you to setup a testing environment, and publish changes to your live server via a simple git push command! This, along with using Ruby on Rail’s database migration tools makes for a powerful environment that will not only allow you to publish code changes to your live site, but also track database schema changes and apply them as well!