Table of Contents
How to Create a new Repository on GitHub
In the last tutorial, we have learned how to make use of Git clients if you are not comfortable using CLI. Now we will learn how to create a new repository on GitHub. Creating a new GitHub repository is very easy and can be learned easily.
Now in this tutorial, we will guide you on creating a new GitHub repository. You can create a repository at github.com by following the below steps.
- Login to github.com, go to the upper right corner and click on the “+” button.
2. Click on New Repository
Give Repository a simple name, say simple-web-app.
You can provide a description of the repository which you are creating, though this is an optional field.
Also, you can choose to make the repository either
- public – Visible to all
- private – Just to you
- README – You also have an option to “Initialize this repository with a README”
If selected a README.MD (markdown file) gets created in the repository and lies on the root.
A README.MD file is nothing but a file that acts as a guide for the functionality of the repository. The README file is written in Markdown scripting.
If you want to learn more on how to write a markdown page, please go throughout the tutorial on Markdown.
- .gitignore– While creating a repository, we may want to block uploading certain files to GitHub Repository which we don’t require. For example, files getting creating on building the project. These files are system specific files which are different for different users.
Such as target/* folder in a maven build java project.
For simplicity, let’s skip creating README and .gitignore for time being.
Hit “Create Repository”, a repository will be created.
The repository will then be allocated a URL and will store all the source code.
The pattern of the URL follows
To be able to clone the project into different machines, we will use git clone command.
But first, let’s put our skeleton code into it.
Open a “Terminal” in Mac or Unix, or in Windows using Command Prompt.
Navigate to the skeleton project, and initialize it as a git managed the project by typing.
Make sure you are inside the project folder.
$ git init
when we did “ls” to the file, it only enlisted index.html.
After a git init, it has created a hidden file called .git, which will maintain the state of git files and the branch.
We’ll discuss more on the branching in Upcoming tutorials. The intention of the current tutorial is to show how Git manages different states of the code files.
Let’s tell git to add up all the new/updated files to be able to push to GitHub.
Either we can specify file one by one or simply use “.” to represent all files.
$ git add index.html
$ git add .
(. is used to specify all files)
Now, we need to commit what changes that we have denoted git to do.
Every commit that we do, has a message which denotes, what was changed.
Since we added all the files to be able to push to GitHub
We commit these changes with a message by
$ git commit -m “Added index.html skeleton”
To push the changes, we need to execute the below command
$ git push -u origin master
origin – origin is a repository location where the code will be uploaded or pushed.
master – git maintain different branch, the master is the main branch, where we want the code to be pushed.
Since there is no origin set, we need to set the remote origin first.
The URL is the location, appended with “.git” at the last.
$ git remote add origin https://github.com/amarkum/simple-web-app.git
In a nutshell, run the below command to push the local files to remote.
git init git add. git commit -m "Added index.html skeleton" git remote add origin https://github.com/amarkum/simple-web-app.git git push -u origin master
The first time, you will need to enter the ID and password for GitHub.
Once set, it won’t ask for the password again.
Below you can see, our skeleton project’s file is added to the project.
As you can see, the commit message is displayed with the username in GitHub Webpage.
We can configure the username and other attributes, which will be discussed in subsequent tutorials.
In this tutorial, we learn how to create a new repository on GitHub and publish our local project to the repository. In the Next tutorial, we’ll learn how to clone the published code into a different machine, make desired changes and publish them back to GitHub repositories.