How To

How to Create Your First Repository on Github

Create a Repository

To create a new repository, first log in to Github or register for a new account. Once logged in, click on the Create New button in the top-right corner of the screen, followed by the Repository link in the drop-down list that appears.

You will see the create repository screen:

The repository name and description can be anything you wish, and for this example “muo_demo” was used as the name. Leave the rest of the fields as they are / blank, and hit the Create new Repository button. You will be brought to a page displaying your new blank repository.

Initiate Local Repository

Now that a repository on Github has been created, you need to initialize the repository on your local PC. Run the following commands in the terminal to create a blank directory, and add a Readme.md file.

mkdir myrepo
cd myrepo
echo "# My Test Repository" > Readme.md
echo "A temporary file" > temp.txt

When viewing a repository on Github, the contents of the Readme.md file is always displayed to describe the repository, or as the first page of the manual. The .md file extension stands for markdown format, and if you’re unfamiliar with Markdown, check out our excellent Markdown format cheat sheet.

This printable Markdown cheat sheet provides everything you need to know about Markdown formatting at a glance. Keep it handy and never be confused again.

You can now initiate the repository within the terminal with the commands.

git init
git remote add origin https://github.com/mdizak/muo_demo.git

In the second command, you need to change the “mdizak” to your Github username, and the “muo_demo” part to the name of your repository. For example, if your Github username is “johndoe” and the name of your repository is “test_repo”, the command would be:

git remote add origin https://github.com/johndoe/test_repo.git

First Commit

You can now sync the local and Github repositories, and add the two files to Github, with the following commands in terminal.

git add Readme.md temp.txt
git commit -m "My first commit"
git push -u origin master

You will be prompted for your Github username and password, and upon successful entry the two files will be uploaded to your Github repository. If you reload your Github repository in your browser, you will now see the two files along with the “My Test Repository” header within the Readme.md file.

Large Commit Messages

Instead of only specifying a small single line commit message, it is also possible to include a larger text message. In your favorite text editor, enter the contents of the commit message, which can be as large and as many lines as desired. When you commit the latest changes, use the command.

git commit --file=/path/to/commit.txt

Ensure the command points to the text file of your commit message, and its contents will be used instead of the single line message defined via the -m option.

Deleting Files

Deleting files is done in much the same way, except for using the above git add command, we use the git rm command. To delete the temp.txt file you previously added, run the following commands in terminal.

git rm temp.txt
git commit -m "Deleting temp file"
git push -u origin master

You will be prompted for your username and password again, and once done, the temp.txt file will be deleted from your Github repository. That’s all there is to it!

What's your reaction?

Excited
4
Happy
4
In Love
3
Not Sure
4
Silly
3

You may also like

Leave a reply

Your email address will not be published. Required fields are marked *