To use GitHub, you'll have to prepare your work environment first. This part only has to be done once.
-
Install git on your computer using
gem install gitor follow the instructions on githowto.com -
Configure git on your computer. Make sure these correspond with your GitHub account settings.
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
- Work through GitHub's introductory tutorial to learn the basics of version control with git. Keep a bookmark to the Git Cheat Sheet for reference.
We'll presume you have a project you've been working on that you'd like to version control, but ideally you'd follow this process on an empty directory before you begin development.
-
cdto your project's root directory. -
Initialize a git project in this directory with
git init -
Add all files in your project to your local git repository with
git add . -
Commit your project’s current state to git version control with
git commit –m "Initial commit" -
Go to your GitHub account and create a repo for your project to reside in by clicking the icon in the upper-right corner.
-
When you create the repo, you will be redirected to notes for connecting your local machine’s repo to your GitHub repo:
git remote add origin [email protected]:github-handle/repo-name.git
- Push your commits to the remote repository with
git push -u origin master
-
As you work on your project, add new files and modifications to your repo with
git add .orgit add filename, then commit changes withgit commit –m "commit notes". Replace "commit notes" with a useful, self-explanatory summary of your changes. -
The
git push –u origin masteryou used to get your project onto GitHub attaches your local master branch to GitHub's, so now a simplegit pushwill push your new commits to your GitHub repo. -
You can push whenever you want. If you have made several commits without pushing, they will all go at once when you do.
-
Use
git logto see a history of your commit changes andgit statusto see the status of your present work. -
Now try doing some more advanced things like reverting, pulling, making new branches, etc by working through some of the attached resources listed at the bottom of the page.
Forking a repo means creating your own copy of someone else's public repository in order to experiment or contribute your own changes. A pull request is a means of alerting the original author that you have changes you'd like merged into the original project. The owner of the original repository can review your changes and choose whether or not to "pull" them in and make them available to everyone.
-
Go to original author’s repo on GitHub and fork it into a repo on your account.
-
Clone your forked repo onto your local computer
git clone [email protected]:your-git-handle/reponame.git
-
If you get
error: port 22 connection refused, it’s probably an issue with GitHub not being able to find your SSH key. Here’s a solution: http://stackoverflow.com/questions/7953806/github-ssh-via-public-wifi-port-22-blocked -
Create a new branch for your repo. This is where you will make your changes. We will work from a new branch, leaving the original master branch unchanged. This will later allow us to submit a pull request without getting merge conflicts with the original branch. The new branch we will create will start off identically to the master branch:
git checkout origin -b <new-branch-name>
-
We are now working on the branch. Edit, add, delete the project files as you see fit in this branch.
-
Commit changes
-
Attach your new branch to your GitHub repo with
git remote add upstream https://github.com/YourGitHandle/Reponame.git
-
Push your commit
-
Go to your GitHub repo. Go to your branch. Submit the pull request.
-
The original author may now authorize the pull request. Once authorized, the author can now merge the new branch into the master branch with:
git checkout <new-branch-name>
git merge master