Setting Up Your First GitHub Repository: A Step-by-Step Guide
-
Ahmed Muhi
- 14 Apr, 2024

Introduction
What happens if your laptop died tomorrow?
If youâre only using Git locally (like we learned in Part 1 - Understanding Git), your code dies with it. All those commits, that careful history, your hard work â gone.
Thatâs where GitHub comes in.
GitHub takes your local Git repository and gives it three superpowers:
- Immortality â Your code lives in the cloud, surviving any hardware disaster
- Accessibility â Work on your project from any computer, anywhere
- Collaboration â Share with teammates without email attachments or USB drives
Think of it this way: Git is your time machine. GitHub is your time machineâs backup in the cloud, plus a way to let others use it too.
Today, weâll take that repository you created in Part 1 and:
- Push it to GitHub (making it disaster-proof)
- Set up VS Code for easier workflows (no more memorizing commands)
- Create your first pull request (the foundation of collaboration)
In 30 minutes, youâll go from âmy code is safe on my laptopâ to âmy code is immortal and shareable.â
Ready to give your repository superpowers? Letâs start by creating your GitHub account.
Creating a GitHub Account
Before we create your account, letâs address the elephant in the room: why GitHub?
Simple answer: GitHub is where the code lives. With over 100 million developers and most open source projects hosted here, itâs the center of the software development universe. While alternatives like GitLab and Bitbucket exist, GitHub is where youâll find the libraries you use, contribute to projects you love, and showcase your work to potential employers.
Best part? Everything we need is completely free. Forever. Private repositories, unlimited collaborators, all the core features â no credit card required.
Setting Up Your Account
Head to github.com and letâs get you set up. The signup process is straightforward, but let me guide you through the important decisions:
Your Username â Choose Wisely
This is more important than you might think. Your username becomes:
- Your GitHub URL:
github.com/YOUR-USERNAME
- Part of every repository URL you create
- How other developers will remember and find you
- Often the first thing employers see when they Google you
Most developers use either:
- Their real name:
jane-smith
orjohnchen
- A consistent professional handle they use everywhere
â ď¸ While you can change it later, doing so breaks all existing links to your repositories. Choose something youâll be happy with long-term.
Your Email Address
GitHub needs this for important notifications and account recovery. A few things to know:
- GitHub will send a verification code here (check spam if it doesnât arrive in 2 minutes)
- This email can be hidden from public view (weâll show you how)
- Remember in Part 1 when we configured
git config --global user.email
? You can use a GitHub-provided privacy email for that too!
Privacy Tip: After signing up, GitHub provides a no-reply email address like
12345678+username@users.noreply.github.com
. This lets you make commits without exposing your real email. Weâll set this up in your account settings.
Creating Your Account
- Enter your chosen username, email, and a strong password
- GitHub might ask about email preferences â your choice on product updates
- Complete the verification puzzle (proves youâre human)
- Enter the verification code sent to your email
After Signing Up
Once you verify your email, GitHub might:
- Ask about your interests and experience level â feel free to skip this
- Show you a personalized dashboard â donât worry about all the options yet
- Suggest creating your first repository â perfect, thatâs exactly what weâre doing next!
What Youâve Just Joined
Congratulations! đ Youâre now part of the worldâs largest developer community. This same account will:
- Become your coding portfolio (employers look at this)
- Track your contribution history (that green squares graph you might have seen)
- Let you contribute to any open source project
- Follow you throughout your entire development career
Quick Troubleshooting
Username taken? Try adding:
- Your middle initial:
john-m-smith
- Numbers (birth year works):
jsmith1995
- A descriptive suffix:
jsmith-dev
Using a school/work email? Some institutions have restrictions. If you have issues, try a personal email instead.
Already have an account? No problem! Use âSign inâ instead. Forgot your password? GitHubâs recovery process is straightforward.
Setting Up Privacy (Optional but Recommended)
Letâs quickly protect your email privacy:
- Go to Settings â Emails (or direct link)
- Check âKeep my email addresses privateâ
- Note your no-reply address that appears (like
12345678+username@users.noreply.github.com
) - You can now use this in your Git config to keep commits private!
Perfect! Your GitHub account is ready. Youâve joined a community where your code can live forever, survive any hardware failure, and be shared with the world (or kept private â your choice).
Ready to upload that repository from Part 1? Letâs make your code immortal!
Creating Your First GitHub Repository
Remember that repository from Part 1 sitting on your computer? Itâs time to give it a home in the cloud.
You have two options when creating a GitHub repository: start fresh on GitHub, or push an existing local repository (which is what weâll do). Since you already have commits and history from Part 1, weâll take the âpush existing repositoryâ approach.
Finding Your Way to Repository Creation
Once youâre logged into GitHub, youâll see your avatar in the top-right corner. Click it and select âYour repositoriesâ from the dropdown. This is your repository dashboard â think of it as your code library.
Youâll see a green âNewâ button. Click it, and letâs set up your repositoryâs new home.
Naming and Configuring Your Repository
Now youâre looking at the repository creation form. Letâs walk through each decision:
Repository Name
Letâs call it my-first-project
to match what we created in Part 1. GitHub will show you if the name is available with a green checkmark.
Tip: Repository names become part of the URL. Keep them lowercase with hyphens instead of spaces. Good:
my-awesome-project
. Avoid:My Awesome Project!
Description (Optional but Recommended)
Add something like: âLearning Git and GitHub fundamentals - my first repository!â
This helps you remember what this project was about when you look back in six months.
Public or Private â The Big Decision
Hereâs where you decide who can see your code:
Choose Public if:
- You want to build your portfolio (employers love seeing active GitHub profiles)
- Youâre learning and want to share your progress
- You might want contributions or feedback from others
Choose Private if:
- This contains sensitive information
- Itâs client work under NDA
- Youâre just experimenting and not ready to share
For our learning project, I recommend Public. You can always change this later in settings.
Initialize This Repository â IMPORTANT
Hereâs the critical part: youâll see checkboxes for:
- Add a README file
- Add .gitignore
- Choose a license
Leave ALL of these unchecked!
Why? You already have a repository with commits from Part 1. If GitHub creates files here, youâll have two different histories that conflict. We want a completely empty repository thatâs ready to receive your existing work.
Creating Your Repository
With everything configured:
- Name:
my-first-project
- Description: Added
- Visibility: Your choice (I suggest Public)
- Initialization options: All UNCHECKED
Click the green âCreate repositoryâ button.
What Youâll See Next
Perfect! GitHub just created your repositoryâs home. Youâll see a page with QuickSetup instructions. GitHub is smart â it knows this repository is empty and gives you exactly the commands you need.
Notice it says ââŚor push an existing repository from the command lineâ â thatâs us! We have an existing repository from Part 1.
The page shows you these commands:
git remote add origin https://github.com/YOUR-USERNAME/my-first-project.git
git branch -M main
git push -u origin main
Donât run these yet! Let me explain what each line does in the next section.
A Quick Celebration
Take a moment to appreciate what just happened:
- You created a home for your code in the cloud
- Your repository has a URL anyone can visit (if public)
- Youâre about to connect your local work to the internet
Your code is one step away from being immortal. Ready to make the connection?
Connecting Your Local Repository to GitHub
Your GitHub repository is ready and waiting. Now letâs connect your local repository from Part 1 to its new home in the cloud.
Understanding What Weâre About to Do
Think of this like setting up a backup drive for your computer. Your local repository (on your computer) needs to know where its backup location (GitHub) is. In Git terms, this backup location is called a âremote.â
Remote: A link between your local repository and another repository (usually online) Origin: The nickname Git uses for your main remote (you could call it anything, but âoriginâ is the convention)
Itâs like saving GitHubâs phone number in your contacts as âGitHubâ instead of typing the full number every time.
Making the Connection
Open your terminal and navigate to your Part 1 repository:
cd path/to/my-first-project
Letâs check that youâre in the right place:
git status
You should see something like âOn branch mainâ and your files listed. Good? Letâs connect to GitHub.
Remember those commands GitHub showed you? Hereâs the first one:
git remote add origin https://github.com/YOUR-USERNAME/my-first-project.git
Replace YOUR-USERNAME
with your actual GitHub username. This command says: âGit, I want to add a remote connection called âoriginâ that points to my GitHub repository.â
Verifying the Connection
Letâs make sure it worked:
git remote -v
You should see:
origin https://github.com/YOUR-USERNAME/my-first-project.git (fetch)
origin https://github.com/YOUR-USERNAME/my-first-project.git (push)
Perfect! Your local repository now knows about GitHub. The (fetch)
means you can download from GitHub, and (push)
means you can upload to GitHub.
A Quick Note About Branch Names
GitHub showed you another command:
git branch -M main
This ensures your branch is called âmainâ (the modern standard). If you followed Part 1, youâre already using âmain.â You can verify with:
git branch
If it shows * main
, youâre all set! Skip to the next section.
If it shows * master
, letâs rename it to match GitHubâs expectation:
git branch -M main
This command renames your current branch from âmasterâ to âmainâ. The -M
means âmove/rename even if the target already exists.â After running this, git branch
should now show * main
.
Why âmainâ instead of âmasterâ? The Git community shifted to âmainâ as the default branch name in 2020. GitHub creates new repositories with âmainâ by default, so weâre aligning with that standard.
The Connection is Ready
Right now:
- â Your local repository exists with all your commits
- â Your GitHub repository exists (empty, waiting)
- â They know about each other (connected via âoriginâ)
- â Your code isnât on GitHub yet (thatâs next!)
Think of it like this: youâve exchanged phone numbers with GitHub, but you havenât sent any messages yet. Ready to push your code to the cloud?
Pushing Your Code to GitHub
This is it â the moment your code becomes immortal. Letâs push your local repository to GitHub and watch the magic happen.
Understanding Your First Push
Remember exchanging phone numbers with GitHub? Now itâs time to send your first message â all your commits, all your history, everything you built in Part 1.
The command GitHub showed you is:
git push -u origin main
Let me break this down:
git push
â Send your commits to a remote repository-u
â Sets up tracking (like setting a default recipient for your messages)origin
â Where to send it (that GitHub connection we just created)main
â Which branch to push
The -u
flag is clever â after this first push, you can simply type git push
without specifying where. Git remembers.
The Moment of Truth
Take a deep breath and run:
git push -u origin main
What Happens Next: Authentication
Hereâs something important: GitHub needs to verify itâs really you. Youâll likely see one of these scenarios:
Scenario 1: Browser Opens Automatically A browser window might pop up asking you to authorize Git. This is GitHubâs preferred method â click âAuthorizeâ and youâre done!
Scenario 2: Username/Password Prompt You might see:
Username for 'https://github.com':
If this happens:
- Enter your GitHub username
- For password, youâll need a Personal Access Token (not your GitHub password!)
Note: GitHub stopped accepting passwords in 2021 for security. If you need a Personal Access Token, hereâs the quick version:
- Go to GitHub Settings â Developer settings â Personal access tokens
- Generate new token (classic)
- Select ârepoâ scope
- Copy the token and use it as your password
Donât worry if this feels complex â you only do it once. Git remembers your credentials.
Watching the Upload
After authentication, youâll see something beautiful:
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (10/10), 1.23 KiB | 1.23 MiB/s, done.
Total 10 (delta 0), reused 0 (delta 0)
To https://github.com/YOUR-USERNAME/my-first-project.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
This is Git copying your entire history to GitHub. Every commit, every change, everything â now safely in the cloud.
The Victory Lap
Go back to your browser and refresh your GitHub repository page.
đ YOUR CODE IS THERE! đ
You should see:
- All your files
- Your commit history
- That README you created in Part 1
- A green âCodeâ button (anyone can now download your project if itâs public)
Try this: Open GitHub on your phone and navigate to your repository. There it is â accessible from anywhere in the world.
Testing Your New Superpower
Letâs prove your code is truly safe. Make a small change locally:
echo "This line was added after pushing to GitHub" >> README.md
git add README.md
git commit -m "Test commit after initial push"
Now push again â notice how simple it is this time:
git push
Thatâs it! No -u origin main
needed. Git remembers where to push. Refresh GitHub and your new change appears instantly.
What Youâve Accomplished
Take a moment to appreciate this:
- â Your code exists in two places (local + cloud)
- â If your computer dies, your code survives
- â You can access your code from any device
- â Others can see your work (if public) and learn from it
- â
Every future commit can be backed up with a simple
git push
Remember that 2 AM panic scenario from Part 1? Now itâs impossible. Your code is immortal.
A Small Challenge
Want to really feel the power? Hereâs something brave:
- Create a new folder somewhere else on your computer
- Clone your repository:
git clone https://github.com/YOUR-USERNAME/my-first-project.git
- Watch your entire project appear from thin air
You just proved you can recover your work from anywhere. Howâs that for peace of mind?
Ready to learn the easier way to do all this with VS Code?
Using VS Code for GitHub
Youâve learned the Git commands â now letâs look at how most developers work day-to-day. VS Code provides a visual interface for the same Git operations you just learned.
Installing VS Code
If you donât have VS Code yet, download it from code.visualstudio.com. Itâs free and works on all platforms.
Adding GitHub Integration
VS Code has built-in Git support, but the GitHub extension adds helpful features:
- Open VS Code and press
Ctrl+Shift+X
(or click the Extensions icon) - Search for âGitHub Pull Requests and Issuesâ
- Install it and restart VS Code if prompted
Opening Your Repository
Open your project folder in VS Code:
- File â Open Folder â Select your
my-first-project
directory
Youâll see your files in the sidebar and can edit them directly.
The Source Control Panel
Click the Source Control icon in the sidebar (third icon down, looks like a branch). This is where youâll do most of your Git work.
Hereâs how VS Code maps to the commands you know:
Making changes:
- Edit any file in the editor
- Changed files appear in the Source Control panel
- The âMâ means modified (just like
git status
showed you)
Staging files:
- Hover over a changed file and click the
+
icon - This runs
git add
for that file - The file moves to âStaged Changesâ
Committing:
- Type your message in the text box at the top
- Press
Ctrl+Enter
or click the checkmark - This runs
git commit -m "your message"
Pushing:
- Click the
...
menu in the Source Control panel - Select âPushâ
- This runs
git push
Understanding the Visual Feedback
VS Code shows you whatâs happening:
- Blue numbers on folders show how many files changed inside
- Color coding in the editor: green lines for additions, red for deletions
- Status bar (bottom left) shows your current branch
Everything you see here corresponds to a Git command you already know. The interface just makes it faster to execute them.
Taking Stock of Your New Powers
Letâs pause and appreciate what you can now do. You started this article with code trapped on your computer. Now look where you are:
Your code lives in three places:
- â Your local repository (with full history)
- â GitHubâs cloud (safe from any disaster)
- â VS Codeâs visual interface (making it all effortless)
You can work two ways:
- Use commands when you need precision or automation
- Use VS Code when you want speed and visual feedback
Try this: Close VS Code, delete your local folder (yes, really!), then clone it back with:
git clone https://github.com/YOUR-USERNAME/my-first-project.git
Everything returns. Your code, your history, every commit. Thatâs the power of what youâve built.
Conclusion: Your Code Is Truly Safe
Remember the promise from Part 1? We said youâd never lose code again. Now that promise extends beyond your computer.
Youâve transformed from someone working alone on one machine to someone who can:
- Access your code from anywhere
- Share your work with the world
- Recover from any disaster
- Choose between command line and visual tools based on what feels right
Your repository isnât just backed up â itâs alive on the internet, ready to grow and evolve.
Whatâs Next: Collaboration and Automation
So far, youâve been working solo. Your repository is like a single-player game â safe and functional, but isolated.
In our next article, weâll unlock multiplayer mode. Youâll discover pull requests â GitHubâs powerful feature that transforms your repository from a backup into a collaboration hub.
More intriguingly, youâll see how pull requests arenât just about code review. Theyâre events that can trigger automated workflows. Every pull request can run tests, check code quality, even deploy applications â all automatically.
Ready to make your repository work with others and FOR you?
Continue to Part 3: [GitHub Pull Requests: Your Gateway to Collaboration and Automation] â
Youâve completed Part 2 of the GitHub Actions series! Your code is now immortal and accessible from anywhere. Next, weâll make it collaborative and intelligent.