Git Workflow Explained: Fork, Clone, Branch, Commit, Push, Pull Request & Merge

Git Workflow Explained: Fork, Clone, Branch, Commit, Push, Pull Request & Merge

When contributing to open-source projects, developers commonly use Git and GitHub to manage code changes. Understanding the complete workflow—from forking a repository to merging code—is essential for collaborating effectively with other developers.

In this guide, you'll learn the complete Git workflow used by many open-source projects such as the Processing Foundation project.

What is Git?

Git is a distributed version control system that helps developers:

  • Track code changes
  • Collaborate with teams
  • Manage project history
  • Roll back unwanted changes
  • Work on multiple features simultaneously

Benefits of Git

✅ Fast and lightweight

✅ Supports collaboration

✅ Maintains complete history

✅ Enables branching and merging

✅ Widely used in software development

What is a Repository?

A repository (repo) is a storage location that contains:

  • Source code
  • Project files
  • Documentation
  • Configuration files
  • Version history

Example:

processing4/
├── src/
├── examples/
├── libraries/
├── README.md
└── .git/

Repositories can be hosted on platforms such as:

Step 1: Fork the Repository

A fork creates your personal copy of someone else's repository on GitHub.

Why Fork?

You usually don't have direct write access to open-source projects.

Instead, you:

  1. Fork the repository
  2. Make changes in your fork
  3. Submit a Pull Request

Original Repository

processing-foundation/processing4

Your Fork

your-account/processing4

GitHub Workflow

Upstream Repository


Fork


Your GitHub Repository

Step 2: Clone the Repository

After forking, download the project to your computer.

Clone Command

git clone https://github.com/your-account/processing4.git

Move into the project directory:

cd processing4

What Happens?

Git downloads:

  • Source code
  • Branches
  • Commit history
  • Project files

You now have a local copy on your machine.

Step 3: Create a New Branch

Never work directly on the main branch.

Create a feature branch:

git checkout -b feature-branch

Example:

git checkout -b fix-login-bug

Why Use Branches?

Branches allow you to:

  • Work safely
  • Isolate changes
  • Prevent breaking production code
  • Collaborate efficiently

Branch Structure

main
├── fix-login-bug
├── update-ui
└── add-report-feature

Step 4: Edit Files

Now make your code changes.

Example:

sketch.pde

Modify:

background(255);
ellipse(50, 50, 80, 80);

Git detects the file has changed.

Check status:

git status

Output:

modified: sketch.pde

Step 5: Stage and Commit Changes

Stage Files

Add files to Git's staging area.

git add sketch.pde

Or add all files:

git add .

Create a Commit

Commit the changes:

git commit -m "Fix drawing issue"

What is a Commit?

A commit is a snapshot of your project at a specific point in time.

Example:

a3f9c1e

Every commit receives a unique hash.

Commit Best Practices

Good:

git commit -m "Add user profile validation"

Bad:

git commit -m "update"

Step 6: Push to GitHub

Upload your branch to GitHub.

git push origin feature-branch

Result

Local Branch


GitHub Fork

Your changes are now visible online.

Step 7: Open a Pull Request

A Pull Request (PR) proposes your changes to the original project.

Workflow

Your Fork


Pull Request


Original Repository

Example

feature-branch

main

Pull Request Includes

  • Code changes
  • Commit history
  • Description
  • Discussion
  • Review comments

Example title:

Fix issue with sketch rendering

Example description:

This PR fixes rendering glitches when drawing shapes.

Step 8: Review and Merge

Project maintainers review your code.

Possible outcomes:

Approved

✓ Ready to merge

Changes Requested

Please update validation logic.

Commented

Can you improve performance?

Merge Process

Once approved:

Feature Branch


Merge


Main

Your contribution becomes part of the official project.

Complete Git Workflow Diagram

1. Fork


2. Clone


3. Create Branch


4. Edit Files


5. Stage & Commit


6. Push


7. Pull Request


8. Review & Merge

Useful Git Commands

CommandDescription
git cloneDownload repository
git statusShow file changes
git checkout -bCreate branch
git add .Stage files
git commit -mCreate commit
git pushUpload changes
git pullDownload updates
git branchList branches
git mergeMerge branches
git logView commit history

Best Practices

1. Commit Frequently

Small commits are easier to review.

2. Write Meaningful Messages

Good:

git commit -m "Add password validation"

3. Use Feature Branches

Avoid working directly on:

main

4. Pull Before Pushing

git pull origin main

5. Keep Pull Requests Small

Smaller PRs get reviewed faster.

Conclusion

Git is the foundation of modern software development and open-source collaboration. By following the workflow of Fork → Clone → Branch → Edit → Commit → Push → Pull Request → Merge, developers can safely contribute to projects, collaborate with teams, and maintain a clean project history.

Mastering these Git fundamentals will make you more productive and help you contribute confidently to open-source projects and professional development teams.

Souy Soeng

Souy Soeng

Hi there 👋, I’m Soeng Souy (StarCode Kh)
-------------------------------------------
🌱 I’m currently creating a sample Laravel and React Vue Livewire
👯 I’m looking to collaborate on open-source PHP & JavaScript projects
💬 Ask me about Laravel, MySQL, or Flutter
⚡ Fun fact: I love turning ☕️ into code!

Post a Comment

CAN FEEDBACK
close