Lesson 31 of 60 – Creating a GitHub Repository
52%

Creating a GitHub Repository

A GitHub repository is a project space where you can store source code, documentation, configuration files, and Git history. Creating a repository is one of the first steps when starting a project on GitHub.

Note: A GitHub repository can be created for a new project or used as a remote repository for an existing local Git project.

1. What is a GitHub Repository?

A GitHub repository is a project space hosted on GitHub. It can contain source code, documentation, images, configuration files, and Git history.

my-project/
├── index.html
├── style.css
├── script.js
└── README.md

2. Why Create a GitHub Repository?

A repository provides a central location for managing and sharing project files.

  • Store project code
  • Track changes with Git
  • Share projects
  • Collaborate with developers
  • Manage issues
  • Review changes
  • Maintain project history

3. Creating a Repository on GitHub

The general process for creating a repository is:

  1. Sign in to GitHub.
  2. Open the repository creation option.
  3. Enter a repository name.
  4. Add an optional description.
  5. Select the appropriate visibility.
  6. Configure optional repository files.
  7. Create the repository.

4. Repository Name

The repository name identifies the project on GitHub.

Examples:

student-management
my-portfolio
online-library
weather-app

Choose a clear name that describes the project.

5. Repository Description

A repository description briefly explains what the project does.

Example:

Student management system built with PHP and MySQL.

A clear description helps visitors understand the purpose of the repository.

6. Public Repository

A public repository is intended to be visible to people according to the repository's access settings.

Public repositories are commonly used for open-source projects, learning projects, portfolios, and examples.

7. Private Repository

A private repository restricts access to authorized users.

Private repositories can be useful for projects that should not be publicly accessible.

8. Adding a README File

A README file provides information about the project.

README.md

It can contain:

  • Project description
  • Features
  • Installation instructions
  • Usage instructions
  • Examples
  • Contribution information

9. What is README.md?

README.md is a Markdown file commonly used to document a project.

GitHub automatically displays the README on the repository's main page when it is present.

10. Adding a .gitignore File

A .gitignore file tells Git which files and directories should normally not be tracked.

Examples of files that may be ignored include:

.env
node_modules/
*.log

11. Choosing a License

A license can describe how others may use, modify, and distribute project code.

When creating a repository, GitHub may provide options for adding a license file.

12. Creating an Empty Repository

You can create a repository without automatically adding files. This can be useful when you already have a local Git project and want to connect it to GitHub.

Local Project
     ↓
Git Repository
     ↓
GitHub Empty Repository

13. Creating a Repository for an Existing Project

If you already have a project on your computer, you can create a GitHub repository and then connect your local Git repository to it.

git remote add origin https://github.com/username/project.git

14. Initializing a Local Repository

If your local project is not already a Git repository, initialize it with:

git init

Then check its status:

git status

15. Making the First Commit

After initializing a local repository, add the project files and create a commit.

git add .
git commit -m "Initial project"

The commit records the current project state in Git history.

16. Connecting the Local Repository

Connect the local repository to the GitHub repository using:

git remote add origin https://github.com/username/project.git

The name origin is commonly used for the remote.

17. Verifying the Remote

After adding the remote, verify it using:

git remote -v

Example:

origin  https://github.com/username/project.git (fetch)
origin  https://github.com/username/project.git (push)

18. Pushing the First Branch

After creating a local commit and connecting the remote, push the branch to GitHub:

git push -u origin main

The -u option establishes upstream tracking for the branch.

19. GitHub Repository URL

A GitHub repository normally has a URL based on the account name and repository name.

https://github.com/username/project

The Git remote URL may use the Git URL form:

https://github.com/username/project.git

20. Repository Settings

Repository settings provide options for managing repository configuration, access, features, and other project settings.

The available options depend on the repository and account configuration.

21. Repository Files

A repository can contain many types of project files.

my-project/
├── index.php
├── style.css
├── app.js
├── images/
├── README.md
└── .gitignore

The exact structure depends on the project.

22. Repository Branches

A repository can contain multiple branches for different lines of development.

main
develop
feature-login
bugfix-payment

Branches help developers work on changes independently before integrating them.

23. Repository Issues

GitHub Issues can be used to track bugs, tasks, feature requests, and other project work.

Example:

Issue #12
Add student login validation

24. Repository Pull Requests

Pull requests allow developers to propose changes and discuss them before integrating those changes into another branch.

feature-login
      ↓
Pull Request
      ↓
main

25. Repository Collaborators

Repository access can be provided to other users so that teams can work together.

The actions available to a collaborator depend on the permissions assigned to them.

26. Common Repository Mistakes

  • Using an unclear repository name.
  • Publishing sensitive information accidentally.
  • Forgetting to add a suitable .gitignore.
  • Adding the wrong remote URL.
  • Pushing to the wrong repository.
  • Ignoring project documentation.
  • Choosing repository visibility without considering the project's requirements.

27. Creating a GitHub Repository Workflow

Sign in to GitHub
        ↓
Create Repository
        ↓
Choose Name
        ↓
Choose Visibility
        ↓
Add README / .gitignore if needed
        ↓
Create Repository
        ↓
Connect Local Git
        ↓
Push Code

28. Complete Local-to-GitHub Example

mkdir my-project
cd my-project

git init

git add .
git commit -m "Initial project"

git remote add origin https://github.com/username/my-project.git

git branch -M main

git push -u origin main

This is a common pattern for publishing an existing local Git project to a newly created GitHub repository.

29. Repository Checklist

  • Choose a clear repository name.
  • Add a useful description.
  • Select the appropriate visibility.
  • Add a README when useful.
  • Add a suitable .gitignore.
  • Choose a license when appropriate.
  • Connect the correct local repository.
  • Verify the remote URL.
  • Push the correct branch.

30. Summary of Creating a GitHub Repository

Creating a GitHub repository provides a remote project space for storing and collaborating on Git-based projects.

Create Repository
      ↓
Configure Project
      ↓
Connect Git Remote
      ↓
Commit Changes
      ↓
Push to GitHub

For an existing local project, the important commands are:

git init
git add .
git commit -m "Initial project"
git remote add origin URL
git push -u origin main

📌 Key Points

  • A GitHub repository is a project space hosted on GitHub.
  • Repositories can store source code, documentation, and Git history.
  • A repository can be public or private according to its visibility setting.
  • README.md is commonly used for project documentation.
  • .gitignore specifies files Git should normally ignore.
  • A local Git repository can be connected to a GitHub repository.
  • git remote add origin URL adds a remote.
  • git remote -v verifies the remote URL.
  • git push -u origin main can push the first main branch and set upstream tracking.
  • GitHub repositories can use branches, issues, pull requests, and collaborators.
  • Always verify the repository and remote URL before pushing project code.

🧠 Quick Quiz

Question: Which command connects a local Git repository to a GitHub repository using the remote name origin?