A Git repository or repo is a virtual storage of your project. It allows you to save versions of your code, which you can access when needed.
-
Log in to your GitHub account.
-
Click the + button on the upper right corner of the page and select
New repository
. -
Name your repository
my-first-repo
and checkInitialize this repository with a README
. -
Click
Create repository
.
Mabuhay! You now have a new repository named my-first-repo
with a README
markdown file.
Now that you have a remote repository on GitHub, it's time to get a local copy on your computer.
Cloning is the most common way for users to obtain a local copy of a remote repository with existing files.
If you're working with an empty repository, you need to initialize it using git init
to get a local copy. For more information, you can check out this interactive tutorial by Code School and GitHub.
- Go to the repo that you created on GitHub and click on the green
Clone or download
button.
-
Copy the HTTPS link by clicking the copy button or selecting the link and pressing
CTRL + C
. -
Open your console and go to the path where you want to place the local copy of your repository.
$ cd <path-to-directory>
Bonus: If you're using bash, type pwd
to get the present working directory. If you're using cmd, type cd
instead.
- Clone the repository using
git clone
.
$ git clone <repository-https-link>
Ta-da! You can now check the directory where you placed your local copy. You should see a folder with named my-first-repo
with the README
file inside.
Before you start editing, make sure you're familiar with the following terms:
- text editor
- markdown
- README
A text editor is any word processing program that you can use to type and edit text.
Commonly used text editors:
Markdown is a way to style text on the web. You control the display of the document; formatting words as bold or italic, adding images, and creating lists. Mostly, markdown is just regular text with a few non-alphabetic characters thrown in, like # or *.
This file is also created using markdown, thus the .md
file extension!
You can add a README file to your repository to tell other people why your project is useful, what they can do with your project, and how they can use it.
A README file, along with a repository license, contribution guidelines, and a code of conduct, helps you communicate expectations for and manage contributions to your project.
A README is often the first item a visitor will see when visiting your repository. README files typically include information on:
- What the project does
- Why the project is useful
- How users can get started with the project
- Where users can get help with your project
- Who maintains and contributes to the project
If you put your README file in your repository's root, docs
, or hidden .github
directory, GitHub will recognize and automatically surface your README to repository visitors.
Here's an example of a good README template.
-
Open the
README
file insidemy-first-repo
using your favorite text editor, preferably one that allows markdown preview. -
Add the following text below "
# my-first-repo
":
This is a sample repository.
# Authors
* [Alysson Alvaran](https://github.com/alyssonalvaran)
Note: #
translates to the HTML <h1>
tag, ##
translates to <h2>
, and so on. *
translates to a bullet and [text](link)
allows you to insert a hyperlink to a text.
If you don't have a markdown preview feature on your text editor, you can paste your codes here to see what it looks like.
Now that you're done editing, our final step is to push to changes back to the remote repository.
Pushing uploads your local commits to your remote repository.
- Open your console and check the unstages changes that you made.
$ git status
- Add the file to be committed using
git add <filename>
.
$ git add README.md
You may also use git add --all
to add all of the unstaged and untracked files if you're working on multiple files at a time.
- Commit the staged changes to your local repository using
git commit -m <commit-message>
.
$ git commit -m "Initial commit"
Bonus: You can use git log
to display the list of commits that you've made so far.
- Finally, push your commit to the remote repository using
git push <remote> <branch>
.
git push origin main
origin
is the default remote created by GitHub that corresponds to the URL of your repository while main
is the default branch. You'll learn more about these in the next lessons.
You've successfully created and pushed your changes to your first repository!
Feel free to ask and participate in our Gitter chat room!