Collaboration in Git means working together with other developers on the same project using Git and a remote repository (like GitHub, GitLab, or Bitbucket).
Instead of everyone editing the same file and overwriting each other’s work, Git provides a system where:
- Each developer can work on their own copy of the project.
- Changes are tracked and can be merged back together safely.
- The history of all contributions is stored, so nothing is lost.
Collaboration with Forks
- Fork - A fork is simply a copy of someone else’s repository under your own GitHub account.
- You get your own independent version of the project.
- You can make changes freely without affecting the original project.
- Later, if you want your changes to be included in the original project, you create a Pull Request (PR).
For example
Imagine there’s a popular open-source project (say, a calculator app) on GitHub:
- You fork the repository, now you have your own copy.
- You add a new feature, like a Dark Mode.
- After testing, you send a Pull Request to the original project owner.
- If they like your work, they merge your changes into the main project.
- How to Fork a Repository
Step 1: Find the Repository
Go to GitHub and open the repository you want to contribute to.
Example: https://github.com/username/projectStep 2: Click the "Fork" Button
On the top-right corner of the repository page, you’ll see a “Fork” button.
Click it.GitHub will create a copy of that repository in your account.
Step 3: Clone Your Fork
Now, you need the repository on your computer.Open Git Bash / Terminal and run:
git clone https://github.com/your-username/project.git
This downloads your forked repo locally.
Step 4: Make Changes
Open the project folder in your editor (like VS Code).Add new features, fix bugs, or improve documentation.
Step 5: Commit and Push Changes
- Collaboration with Pull Request
- A Pull Request (PR) is a way of telling the project owner: “I’ve made some changes in my fork/branch. Please review them and, if everything looks good, merge them into the main project.”
Think of it as asking for permission to merge your work into the main repository. - Why Do We Use Pull Requests?
- To propose new features or bug fixes.
- To let others review your code before merging.
- To discuss improvements with team members.
- To keep the main branch stable.
- A Pull Request (PR) is a way of telling the project owner: “I’ve made some changes in my fork/branch. Please review them and, if everything looks good, merge them into the main project.”