Setting Up a New Github Project Repository
In this demonstration, I will show you how to create and upload an existing project to a new Github repository.
-
Log in to Github (https://www.github.com/) with the username and password you previously created.
-
From the homepage, click on
New
under the Repositories heading in the left sidebar panel. -
In the
Create a new repository
form, enter a repository name. Usually this will be the same as the project folder name. For this project, the repository name should be “quiz-me
”. Then, click theCreate repository
button, and you will be taken to the main page for your new empty repository. -
Create an initial project commit (a snapshot of the current project state) by entering the following commands:
git add -A git commit -m "Initial commit"
More about these Git commands…▼
The
git add
andgit commit
commands will be run often as you are making changes to your projects and want to save them to the online repository. Thegit add
command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. The-A
option tells Git to include all changes to all files in the project folder. You can view the contents of the staging area with thegit status
command. Thegit commit
command creates the snapshot and saves it to your local repository. Each commit will have a default commit message that you can override with the-m "$MSG"
option to make a more informative description of the changes in that commit.Verify the commit has the correct information by entering the following command:
git log
-
Copy the instructions on the GitHub repository webpage for pushing an existing repository from the command line, and paste them into your terminal. The commands should look something like this (only with the “
...
” replaced with your GitHub username):git remote add origin https://github.com/.../quiz-me.git git push -u origin master
More about these Git commands…▼
The
git remote
command is used configure your local repo to know about remote repos. In this case, it sets the name "origin
" to correspond to the remote repo athttps://github.com/.../quiz-me.git
.The
git push
command is used upload and merge local commits into a remote repo. In this case, the local commits are sent to the remote repo named "origin
", which was set to correspond to the GitHub repo in the previous command. The word "master
" in the command refers to themaster
branch in the local repo, which is the only branch we currently have and was created by default by Git. The "-u
" flag is only used once, the first time a local branch is pushed to a remote repo. In short, its purpose is to configure the local repo to know that the local branch is a "tracking branch" with respect to the remote branch (i.e., that the branches have a direct relationship). For subsequent pushes from themaster
branch, we will need only to enter the commandgit push
(without the additional arguments), and Git will know exactly what we mean. -
Verify that the push was successful by refreshing the Github project page, which should now display the project file structure.
The project repository is now hosted on GitHub!