GitHub's a great tool to maintain your code, but it's definitely a little confusing the first time around (and, possibly, a few times after that). Here is a quick guide on how to use it efficiently.
Once you are all set on the GitHub site, you have to install git on your local machine.
Now you are ready to upload your local files to your repository. To do that, first we must initialize some settings in git:
Open up a terminal and enter the following two commands:
git config --global user.name "Your Name Here"
git config --global user.email "firstname.lastname@example.org"
Make sure that you give your GitHub email address as user.email. As user.name you can enter whatever you like.
After the initial configuration is done, you can synchronize your local files with your repository. Go to the local directory where your project's files reside and enter the command:
With git, you synchronize yor files through commits. Each commit contains files that you specify to be uploaded to GitHub. To add files to a commit enter:
git add example.php
The above will add example.php to the next commit. If you want to add all files and folders, you enter the command:
git add -A
Once you are happy with the files you want uploaded to GitHub, enter the command:
git commit -m "optional message. usually the purpose of this commit, eg. why changes were made"
This will get all files you added ready for uploading to GitHub. To actually upload them, you enter the commands:
git remote add origin https://github.com/yourusername/nameofyourrepository
git push origin master
If you get an error message, it can be that the GitHub repository contains files not currently on your local folder. In that case you have to "pull"(download) them first from GitHub, before you can synchronize your project. To pull files from GitHub you enter the command:
git pull https://github.com/yourusername/nameofyourrepository
After "pulling" has finished, you can try to "push"(upload) your commit again:
git push origin master
That's it! You've "pushed" your local files to your GitHub repository.
Now whenever you make changes to your local files, you can add them to a commit and push them to the repository. You can also pull from the repository to work on other people's commits (if you're working on a team's projects). Another scenario is that you can revert to a previous commit in GitHub, and pull the files from that commit to your local folder to work on them.