Create 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.First: Create A Repo
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.
More about repositories
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 repo, but stored on a different server or computer for easy collaboration, backup, and general awesomeness.
-
Create a new repo
Click New Repository.
Fill out the information on this page. When you’re done, click “Create Repository.”
Congratulations! You have successfully created your first repo!
Next: Create a README for your repo.
While a README isn’t a required part of a GitHub repo, it is a 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.
More about READMEs
If you include a file with the filename “README” in your repo, it will automatically be shown on your repo’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 the github markup repo.
-
Create the README file
In the prompt, type the following code:
$ mkdir ~/Hello-WorldCreates a directory for your project called "Hello-World" in your user directory $ cd ~/Hello-WorldChanges the current working directory to your newly created directory $ git initSets up the necessary Git files Initialized empty Git repository in /Users/your_user_directory/Hello-World/.git/ $ touch READMECreates a file called “README” in your Hello-World directoryOpen 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.
-
Commit your README
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:
More about commits
Think of a commit as a snapshot of your project —code, files, everything — at a particular point in time. More accurately, after your first commit, each subsequent commit is only a snapshot of your changes. For code files, this means it only takes a snapshot of the lines of code that have changed. For everything else like music or image files, it saves a new copy of the file.
$ git add READMEStages 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"The code above executes actions locally, 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 repo and push your commits to it:
More about remotes
A remote is a repo 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
originto the remote that points to your main offsite repo (for example, your GitHub repo).Git supports multiple remotes. This is commonly used when forking a repo.
$ git remote add origin git@github.com:username/Hello-World.gitSets the origin for the Hello-World repo $ git push origin masterSends your commit to GitHubNow if you look at your repository on GitHub, you will see your README has been added to it.
Lastly: Celebrate
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?