Git & GitHub ยท Chapter 24 of 42

GitHub Account & Creating a Repository

GitHub is a website that hosts Git repositories in the cloud, adding features like issue tracking, pull requests, and team collaboration tools on top of Git. To use it, you first need a free GitHub account.

Once signed up, you can create a new repository directly on GitHub's website, which gives you a URL you can clone or push your local project to.

Syntax
git remote add origin https://github.com/username/repo.git

Creating an account

Sign up for free at github.com with an email address and username. Verifying your email lets you create repositories and collaborate with others.

Creating a repository

Click 'New repository' on GitHub, give it a name, choose public or private, and optionally add a README. GitHub then shows you commands to connect a local project.

Example 1 (bash)
git remote add origin https://github.com/alexsmith/my-project.git
git push -u origin main
Output
Branch 'main' set up to track remote branch 'main' from 'origin'.

Connects a local repo to a newly created GitHub repository and pushes the first commits.

Example 2 (bash)
git clone https://github.com/alexsmith/my-project.git
Output
Cloning into 'my-project'...
remote: Enumerating objects: 10, done.

Downloads a full copy of an existing GitHub repository to your machine.

Key points

  • GitHub hosts Git repositories in the cloud.
  • You need a free GitHub account to create repositories.
  • Repositories can be public (visible to everyone) or private.
  • GitHub adds features like issues, pull requests, and Actions on top of Git.
๐Ÿ’ก Note: Public repositories are visible to anyone, so avoid storing secrets or private data in them.

๐Ÿ“ Quick Quiz

1. What is GitHub?

2. What do you need to create a repository on GitHub?

3. What is the difference between public and private repositories?