Thursday, May 8, 2014

How to push a project to Github

In a previous post, I mentioned that every developer should be using Github.  Github is a cloud-hosting service that creates backups of repositories, or projects.  These projects can be viewed, shared, or edited by other members of Github.  Github creates a wonderful experience because it creates a worry-free backup of your work and other people can contribute towards your work, which can create bigger and better projects.  

In order to use Github, you have to be a little bit familiar with a command-line interface, such as terminal for Mac.  It's been a few months since I've pushed a project to Github, so I thought I would go over the steps to both help you and myself.

Before I begin with the initial Github push, there are three basic steps when pushing a project.  First, edit content.  This means editing a piece of code, adding images, added documents, whatever.  Second, you commit the changes, which means you kind of create a save state.  Three, you push the save state to Github.


Step One - Create Your Repository



This is actually an easy step and it doesn't require the command-line interface.  Visit Github and perform the necessary on-screen steps. Be sure to name your repository and remember the name, because we will have to refer to it in step three.   It doesn't matter what you select for the README; we are going to wipe out the settings in a second!

Also, make sure you have a folder on your desktop for your project.  The beauty of Github is that you can work offline and then push your content online.


Step Two - Install Git



Git is required in order to push projects to Github.  If you don't have it installed already, you can actually install it from Terminal.  Follow the steps provided at the Git website.


Step Three - Initialize Git



Now that you have Git installed, you can get started!

In Terminal, cd to your local project folder on your computer.

Type the following in the Terminal:

git init

This creates a git repository in your project folder on your computer.

Then add files to the Git index:

git add .

Commit the added files:

git commit -m 'Whatever you wish to say'

Commiting is like a save state for your project.  You can add messages to help you remember where you are at within your project's progress.  This is added in between the single quotation marks.

Create a connection with Github

git remote add origin https://github.com/username/your-project.git

Make sure to change the your-project to your project's url address. You can get the url from the repository you created through Github.

Push Project to Github

git push -u origin master

This sends your commits in the master branch of Github. Basicaly, this is sending your save state to Github.

Final Thoughts


That's all!  Using Terminal for the first commit and push is required. Once you have done this, you can download a Github client that will make it easier to commit and push; it doesn't require Terminal. I prefer Github for Mac. However, you can always commit and push to Github through Terminal like we just did. This time, this is all you have to do for the next commit and push:

git add .

git commit -m "type your commit message here"

git push origin master



No comments:

Post a Comment