If you are new to coding you have probably heard about GitHub. It is a platform where developers store and share their code. But the heart of GitHub is the repository. A repository or repo for short is like a project folder. It holds all your files and keeps track of every change you make. Learning how to use GitHub repositories can change your workflow for the better. This guide will show you the basics in simple steps. No prior experience needed.
What Is a GitHub Repository?
Think of a GitHub repository as a special folder. This folder lives on the internet. But unlike a normal folder a repo remembers history. You can see who changed what and when. You can also go back to older versions of your files. This feature is called version control. GitHub uses a system called Git to manage this. A repository can be public or private. Public repos let anyone see your code. Private repos are only for you and your team. Many open source projects use public repositories. Companies use private ones for their secret work. Understanding this basic idea helps you start using GitHub repositories with confidence.
How to Create a New Repository
Creating your first repository is easy. First sign in to your GitHub account. On the top right click the plus icon. Then choose New repository. You will see a form. Give your repository a name. Use something short and clear like my-first-project. Then write a description. This tells others what your project does. Next choose if your repo will be public or private. For learning start with public. Then you have an option to add a README file. A README explains your project. Check that box. You can also add a .gitignore file. This file tells Git which files to ignore like temporary files. Choose a license if you want. For now skip the license. Then click Create repository. Congratulations you now have a repo. GitHub will show you your new repository page. You will see your README file there. This is your project home.
Cloning a Repository to Your Local Machine
Your repository lives on GitHub’s servers. But you want to work on your own computer. So you need to clone it. Cloning means making a copy on your local machine. First you need Git installed on your computer. Go to git-scm.com and download Git for your system. Install it with default settings. Then open a terminal or command prompt. On your GitHub repository page click the green Code button. You will see a URL. Copy that URL. Now in your terminal type git clone followed by the URL. It looks like this: git clone https://github.com/yourusername/my-first-project.git Press enter. Git will download the repo to your computer. You will find a new folder with the same name. Move into that folder using cd my-first-project. Now you are inside your local repository. You can add edit or delete files here. Everything you do will be tracked.
Making Your First Commit
A commit is like saving a snapshot of your project. But commits are special because they have a message. The message tells what you changed. Let’s make your first commit. First create a new file. For example make a file called hello.txt. Write “Hello World” inside it. Save the file. In your terminal make sure you are in the repo folder. Then type git status. This shows which files changed. You will see hello.txt in red. That means Git sees it but is not tracking it yet. To start tracking type git add hello.txt. Now type git status again. The file turns green. Now you are ready to commit. Type git commit -m “Add hello.txt with greeting”. The -m flag lets you write a message. Always write clear messages. They help you later. Your first commit is done. You have saved a snapshot of your project at this moment.
Pushing Changes to GitHub
Your commit lives on your local machine. GitHub does not know about it yet. To share your commit you push it. Pushing sends your local changes to the remote repository on GitHub. Type git push. This command uploads your commits. Git may ask for your GitHub username and password. If you set up SSH keys you will not need to enter credentials each time. For now use your username and a personal access token. You can create a token in GitHub settings. After you push go to your repository page on GitHub. Refresh the page. You will see your hello.txt file there. Also your commit message appears in the history. That is how you use GitHub repositories to sync work between your computer and the cloud. Push often to keep your remote repo up to date.
Branching and Merging Basics
Branches are a powerful feature. A branch lets you work on new features without breaking the main code. The default branch is usually called main or master. To create a new branch type git branch new-feature. Then switch to it with git checkout new-feature. Or do both in one command: git checkout -b new-feature. Now make changes on this branch. Edit a file or add a new one. Then commit your changes. Push the branch with git push origin new-feature. Now on GitHub you will see this branch listed. When your feature is ready you merge it back to main. First switch to main: git checkout main. Then pull the latest changes: git pull. Then merge your branch: git merge new-feature. If there are no conflicts the merge is smooth. Conflicts happen when the same line changed in two branches. You must fix them manually. Then commit the merge. Merging keeps your history clean.
Working with Pull Requests
Pull requests are how you propose changes on GitHub. They are common in team projects. Instead of merging locally you create a pull request on GitHub. First push your branch to GitHub. Then go to your repository page. You will see a Compare & pull request button. Click it. Write a title and description for your change. Explain what you did and why. Then click Create pull request. Other team members can now review your code. They can leave comments. They can ask for changes. You can push more commits to the same branch. The pull request updates automatically. When everyone agrees someone merges the pull request. Merging can happen on GitHub with a click. You can also delete the branch after merging. Pull requests make collaboration easy. They allow code review before changes hit the main branch. Even when working alone pull requests help you track your work.
Final Thought
Learning how to use GitHub repositories takes practice. But the basics are simple. Create a repo. Clone it. Make changes. Commit. Push. Branch. Merge. Each step builds on the last. Do not feel overwhelmed. Start with a small project. Maybe a text file or a recipe list. Use Git commands daily. Soon they become second nature. GitHub also has a desktop app. That app can help if you dislike the terminal. But learning the command line gives you more control. Remember every developer started as a beginner. Mistakes are part of the process. You might forget to push. You might create a merge conflict. That is fine. You will learn how to fix these issues. Keep a cheat sheet of common commands. And most important have fun building things. Your GitHub repository is your digital workshop. Fill it with your ideas.
Frequently Asked Questions (FAQs)
What is the difference between Git and GitHub?
Git is the version control system that runs on your computer. GitHub is a website that hosts Git repositories online. You can use Git without GitHub but GitHub adds collaboration features.
Do I need to pay for GitHub repositories?
No. GitHub offers free public and private repositories for everyone. Free accounts have some limits like limited GitHub Actions minutes but for most personal projects it is fine.
How do I delete a repository?
Go to your repository on GitHub. Click Settings. Scroll to the Danger Zone. Click Delete this repository. You will need to type the repo name to confirm. Be careful deletion is permanent.
Can I undo a commit?
Yes. Use git reset HEAD~1 to undo the last commit but keep your changes. Use git reset –hard HEAD~1 to completely remove the commit and changes. Only use –hard if you are sure.
How do I update my local repo with changes from GitHub?
Use git pull. This fetches changes from the remote repo and merges them into your current branch. Do this before you start working to avoid conflicts.
What is a .gitignore file?
A .gitignore file tells Git which files to ignore. Common examples are log files temporary files or secret keys. This keeps your repo clean.
How can I see my commit history?
Type git log. This shows a list of commits with their unique IDs authors dates and messages. Press q to exit.
What is a fork?
A fork is a personal copy of someone else’s repository. You use forks to propose changes to projects you do not own. After forking you can make changes and send a pull request to the original repo.
