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.
Every time you make a commit with Git, it is stored in a repository (a.k.a. "repo"). To put your project up on GitHub, you'll need to have a GitHub repository for it to live in.
Git stores all of your project files in a repository. If you are able to view hidden files on your system, you'll see a subdirectory called ".git" in the project directory where you run
git init. This is where Git stores all of your commits, as well as everything else it needs. In addition to your local, you can also have remote repositories (like GitHub repos). Remote repositories are the same as your local repository, but stored on a different server or computer for easy collaboration, backup, and general awesomeness.
Click New Repository.
Fill out the information on this page. When you're done, click "Create Repository."
Congratulations! You have successfully created your first repository!
While a README isn't a required part of a GitHub repository, it is a very good idea to have one. READMEs are a great place to describe your project or add some documentation such as how to install or use your project. You might want to include contact information - if your project becomes popular people will want to help you out.
If you include a file with the filename "README" in your repository, it will automatically be shown on your repository's front page. Pretty cool, huh? GitHub supports a number of different README formats. The one in this tutorial will result in a basic text file but other formats like .markdown or .textile can be used to render HTML content like links and headers. For more info about the supported markup formats, check out https://github.com/github/markup.
In the prompt, type the following code:
mkdir ~/Hello-World # Creates a directory for your project called "Hello-World" in your user directory cd ~/Hello-World # Changes the current working directory to your newly created directory git init # Sets up the necessary Git files # Initialized empty Git repository in /Users/you/Hello-World/.git/ touch README # Creates a file called "README" in your Hello-World directory
Open the new README file found in your Hello-World directory in a text editor and add the text "Hello World!" When you are finished, save and close the file.
Now that you have your README set up, it's time to commit it. A commit is essentially a snapshot of all the files in your project at a particular point in time. In the prompt, type the following code:
Think of a commit as a snapshot of your project — code, files, everything — at a particular point in time. After your first commit git will only save the files that have changed, thus saving space.
Be warned: git will do it's best to compress your files, but large files and binaries can cause a repository to become bloated and unwieldy. Try to avoid committing things like compressed files (zips, rars, jars), compiled code (object files, libraries, executables), database backups, and media files (flv, psd, music, movies)
git add README # Stages your README file, adding it to the list of files to be committed git commit -m 'first commit' # Commits your files, adding the message "first commit"
So far, everything you've done has been in your local repository, meaning you still haven't done anything on GitHub yet. To connect your local repository to your GitHub account, you will need to set a remote for your repository and push your commits to it.
A remote is a repository stored on another computer, in this case on GitHub's server. It is standard practice (and also the default in some cases) to give the name
origin to the remote that points to your main offsite repository (for example, your GitHub repository).
Git supports multiple remotes. This is commonly used when forking a repository.
git remote add origin https://github.com/username/Hello-World.git # Creates a remote named "origin" pointing at your GitHub repository git push origin master # Sends your commits in the "master" branch to GitHub
Tip: Notice that the path to your remote URL--Hello-World.git--matches the one that you created on GitHub. This is case sensitive, and important to keep the same.
Now if you look at your repository on GitHub, you will see your README has been added to it.
Congratulations! You have now created a repository on GitHub, created a README, committed it, and pushed it to GitHub. What do you want to do next?