This guide will help you quickly create and set up a repository on GitHub and connect it to a local repository on your computer.
-
Go to GitHub:
- Navigate to https://github.com/ and sign in.
-
Start a New Repository:
- In the upper-right corner of any GitHub page, click +, and then click New repository.
- Alternatively, you can go to https://github.com/new.
-
Name Your Repository:
- Enter a name for your repository (e.g.,
my-new-repo
). - Optionally, add a description.
- Enter a name for your repository (e.g.,
-
Choose Visibility:
- Select Public if you want the repository to be visible to everyone, or Private to restrict access to yourself and collaborators.
-
Skip Initializing Options (Optional):
- For this example, we’ll skip adding a README file,
.gitignore
, or license. (You can add these files later from your local machine or GitHub.)
- For this example, we’ll skip adding a README file,
-
Create Repository:
- Click Create repository to generate the repository on GitHub. You’ll be taken to the new repository’s page.
-
Open Your Terminal:
- On your computer, open a terminal (or command prompt).
-
Create a New Folder (if you don’t have one already):
mkdir my-new-repo cd my-new-repo
-
Initialize Git:
- Set up Git for version control in your folder by running:
git init
-
Add a README (Optional):
- Create a README file to describe your project:
echo "# My New Repo" > README.md
-
Stage and Commit Files:
- Stage and commit your files:
git add . git commit -m "Initial commit"
-
Copy the Repository URL:
- On your GitHub repository page, you’ll see a Quick setup section with the repository URL (it looks like
https://github.com/username/my-new-repo.git
). Copy this URL.
- On your GitHub repository page, you’ll see a Quick setup section with the repository URL (it looks like
-
Add the Remote Origin:
- In your terminal, link your local repository to GitHub:
git remote add origin <your-repository-url>
Replace
<your-repository-url>
with the URL you copied. -
Push Your Local Repository to GitHub:
- To upload your code to GitHub for the first time, use:
git push -u origin main
-
Check GitHub:
- Go back to your repository page on GitHub and refresh to see your files.
-
Future Changes:
- After making changes to your files locally, use the following commands to push updates to GitHub:
git add . git commit -m "Describe your changes" git push
- After making changes to your files locally, use the following commands to push updates to GitHub:
You’ve now successfully created a GitHub repository and linked it to your local project! For more details, refer to GitHub’s official documentation.