description: Understand forking, cloning, pull requests, merge conflicts, collaboration, and Git commands using Git and GitHub.
Whether you’re a beginner in coding or collaborating on your first group project, understanding version control is a must. In this article, I’ll walk you through the basics of version control using Git and GitHub, including essential workflows like forking, cloning, collaboration, pull requests, resolving merge conflicts, and more.
📌 What is Version Control?
Version control is a system that tracks changes to your code over time. It allows multiple developers to work on the same codebase without overwriting each other’s work.
Imagine it like Google Docs for code — you can go back to older versions, see who made changes, and collaborate in real-time.
👉 Read more: Atlassian’s guide on Version Control
🔧 Git vs GitHub
- Git is the actual version control system. It's installed on your computer and helps manage local code changes.
- GitHub is a cloud-based platform where your Git repositories are hosted online, allowing collaboration.
🌱 Forking a Repository
Forking is creating a personal copy of someone else's repository on your GitHub account.
Why fork?
- To propose changes to someone else's project
- To experiment safely without affecting the original repo
➡️ Steps:
- Go to the repo on GitHub
- Click the Fork button (top right)
- You now have your own copy to work on!
🧭 Forking vs Cloning a Repository: What’s the Difference?
If you're just starting out with GitHub, you might wonder:
"When should I fork a repo, and when should I clone one?"
Although they may seem similar, forking and cloning serve different purposes and are used in different situations.
🍴 What is Forking?
Forking a repository means creating a copy of someone else’s GitHub repo under your own GitHub account.
✅ Use it when:
- You don’t have write access to the original repo (e.g. open source)
- You want to suggest changes via a pull request
- You want to customize or experiment without affecting the original project
🔁 After forking, you can then clone your fork to your local machine to begin working on it.
📥 What is Cloning?
Cloning is when you download a GitHub repository to your local computer using Git.
✅ Use it when:
- You want to work on the project locally
- You already have access to the repo (e.g. your own project or team project)
- You want to run, edit, or explore the code
🛠️ The clone creates a local working copy of the repository. Any changes you make locally won’t reflect on GitHub until you push them.
🆚 Key Differences
Feature | Forking | Cloning |
---|---|---|
Creates GitHub Copy? | ✅ Yes (in your GitHub account) | ❌ No (just on your computer) |
Requires GitHub? | Yes | No (can be done with just a repo URL) |
Common Use Case | Contribute to open source or copy someone’s project | Work on your own or team repo locally |
Access Level | You don’t need write access to the original repo | Typically used if you have access or after forking |
Next Step | Usually followed by cloning the fork | Can push changes directly if you have access |
🧪 Real-World Example
Let’s say you find a cool open source project like weather-app
on GitHub, and you want to contribute.
Option A: Fork + Clone (Open Source)
- Click Fork → You now have your own copy on GitHub.
- Run:
git clone https://github.com/your-username/weather-app.git
`
- Make changes locally.
- Push and create a pull request to contribute back.
Option B: Clone Directly (Your Own Project)
- Run:
bash
git clone https://github.com/your-username/my-portfolio.git
- Make changes, then push directly to the same repo.
🔑 Summary
🔹 Forking = Copy a GitHub repo to your account
🔹 Cloning = Copy a GitHub repo to your local machine
They often work together:
👉 Fork first → then clone → make changes → push → pull request
🤝 Collaboration & Pull Requests
After forking and making your changes locally, you’ll want to contribute back.
Here’s how collaboration happens:
`bash
Clone your fork
git clone https://github.com/your-username/project-name.git
Create a new branch
git checkout -b feature-branch
Make changes and commit
git add .
git commit -m "Added a new feature"
Push to GitHub
git push origin feature-branch
`
Now, go to your GitHub repo and open a Pull Request (PR) — this asks the original repo owner to review and merge your changes.
🔗 Learn more: GitHub Learning Resources
⚔️ Merge Conflicts
A merge conflict happens when two people edit the same line of code in different ways.
Git will ask you to manually fix the conflict:
`bash
<<<<<<< HEAD
your code
incoming change
feature-branch
`
Fix the section, then:
bash
git add .
git commit -m "Resolved merge conflict"
Pro tip: Use VS Code or GitHub’s web editor to visualize and resolve conflicts easily.
🔍 Code Review
Once a pull request is opened, teammates (or repo owners) can:
- Suggest changes
- Approve the PR
- Leave comments
This encourages better code quality and team learning!
📌 GitHub Issues
Issues are like to-do tasks or bug reports. Use them to:
- Track features
- Report bugs
- Start discussions
You can label issues with tags like bug
, good first issue
, or help wanted
.
🧠 Must-Know Git Commands
Command | Description |
---|---|
git clone |
Download a project |
git status |
See changes |
git add . |
Stage changes |
git commit -m "msg" |
Save a snapshot |
git push |
Upload to GitHub |
git pull |
Download changes |
git branch |
List branches |
git checkout -b branch-name |
Create/switch to new branch |
🚀 Pushing Changes to GitHub
After editing your code:
bash
git add .
git commit -m "your message"
git push origin branch-name
This sends your code to your GitHub repo — ready for collaboration or deployment!
🎯 Final Thoughts
Learning Git and GitHub is a game-changer in modern software development. Whether you're working on solo projects or contributing to open source, these skills will help you stay organized, avoid mistakes, and work better with teams.
🔗 Useful Links
✍️ Have questions or feedback? Drop them in the comments or connect with me on GitHub. Happy coding!
Top comments (0)