Set Up Git
If you've found yourself on this page, we're assuming you're brand new to Git and GitHub. This guide will walk you through the basics and explain a little bit about how everything works along the way.
Download and Install Git
At the heart of GitHub is an open source version control system (VCS) called Git*. Created by the same dudes that created Linux, Git is responsible for everything GitHub related that happens locally on your computer.
*If you don't already know what Git is, take a crash course.
Set Up Git
Username
First you need to tell git your name, so that it can properly label the commits you make.
git config --global user.name "Your Name Here"# Sets the default name for git to use when you commit
Email
Git saves your email address into the commits you make. We use the email address to associate your commits with your GitHub account.
git config --global user.email "your_email@youremail.com"# Sets the default email for git to use when you commit
Your email address for Git should be the same one associated with your GitHub account. If it is not, see this guide for help adding additional emails to your GitHub account. If you want to keep your email address hidden, this guide may be useful to you.
Password caching
The last option we need to set will tell git that you don't want to type your username and password every time you talk to a remote server.
Good to know: You need git 1.7.10 or newer to use the credential helper
Good to know: The credential helper only works when you clone an HTTPS repo URL. If you use the SSH repo URL instead, SSH keys are used for authentication. This guide offers help generating and using an SSH key pair.
Celebrate
Congratulations, you now have Git and GitHub all set up! What do you want to do next?
Creating a new repository
You can create a new repository on your personal account or any organization account where you have sufficient permissions.
- In your user bar at the top right of any page, click the "Create a New Repo" button
- Select the account you wish to create the repo on
- Enter a name, select to make the repo either public or private and click "Create repository"
Good to know: If you do not have Owner or Admin rights in the organization it will say "insufficient permission" in the list.
Fork A Repo
If you've found yourself on this page, we're assuming you're brand new to Git and GitHub. This guide will walk you through the basics and explain a little bit about how everything works along the way.
Contributing to a project
At some point you may find yourself wanting to contribute to someone else's project, or would like to use someone's project as the starting point for your own. This is known as "forking." For this tutorial, we'll be using the Spoon-Knife project.
Step 1: Fork the "Spoon-Knife" repo
To fork this project, click the "Fork" button.
Step 2: Clone your fork
You've successfully forked the Spoon-Knife repo, but so far it only exists on GitHub. To be able to work on the project, you will need to clone it to your local machine.
Run the following code:
git clone https://github.com/username/Spoon-Knife.git# Clones your fork of the repo into the current directory in terminal
Step 3: Configure remotes
When a repo is cloned, it has a default remote called origin
that points to your fork on GitHub, not the original repo it was forked from. To keep track of the original repo, you need to add another remote named upstream
:
cd Spoon-Knife# Changes the active directory in the prompt to the newly cloned "Spoon-Knife" directory
git remote add upstream https://github.com/octocat/Spoon-Knife.git# Assigns the original repo to a remote called "upstream"
git fetch upstream# Pulls in changes not present in your local repository, without modifying your files
More Things You Can Do
You've successfully forked a repo, but get a load of these other cool things you can do:
Push commits
Once you've made some commits to a forked repo and want to push it to your forked project, you do it the same way you would with a regular repo:
git push origin master# Pushes commits to your remote repo stored on GitHub
Pull in upstream changes
If the original repo you forked your project from gets updated, you can add those updates to your fork by running the following code:
git fetch upstream# Fetches any new changes from the original repo
git merge upstream/master# Merges any changes fetched into your working files
Create branches
Branching allows you to build new features or test out ideas without putting your main project at risk. In git, branch is a sort of bookmark that references the last commit made in the branch. This makes branches very small and easy to work with.
Pull requests
If you are hoping to contribute back to the original fork, you can send the original author a pull request.
Unwatch the main repo
When you fork a particularly popular repo, you may find yourself with a lot of unwanted updates about it. To unsubscribe from updates to the main repo, click the "Unwatch" button on the main repo.
Delete your fork
At some point you may decide that you want to delete your fork. To delete a fork, just follow the same steps as you would to delete a regular repo.
Celebrate
You have now forked a repo. What do you want to do next?