home

๐ŸŒ GitHub Collaboration Guide

GitHub is a web-based platform built on top of Git that helps developers collaborate, review code, and manage projects. This guide will walk you through the most common collaboration workflows using Git and GitHub.


๐Ÿ” Workflow Overview

  1. Clone a repository
  2. Create a branch for your feature
  3. Commit and push your changes
  4. Open a Pull Request (PR)
  5. Collaborate & review
  6. Merge the PR into the main branch
  7. Pull the latest changes

๐Ÿ“ฅ 1. Cloning a Repository

To contribute to a project on GitHub, first clone the repository to your local machine.

๐Ÿ”น Example

git clone https://github.com/username/repo-name.git
cd repo-name

This creates a local copy of the remote GitHub repository.


๐ŸŒฟ 2. Creating and Switching Branches

Use branches to work on features or fixes without affecting the main branch.

๐Ÿ”น Create a new branch and switch to it

git checkout -b feature/new-feature

Branch names should be short, lowercase, and use hyphens (-) for readability.


๐Ÿ’พ 3. Committing and Pushing Changes

After editing files:

๐Ÿ”น Stage and commit your changes

git add .
git commit -m "Add new feature: description"

๐Ÿ”น Push your branch to GitHub

git push origin feature/new-feature

origin refers to the GitHub repo. This command creates the remote branch if it doesnโ€™t exist.


๐Ÿ”ƒ 4. Opening a Pull Request (PR)

Go to your repository on GitHub. Youโ€™ll see an option to โ€œCompare & pull request.โ€

๐Ÿ“ Pull Request Checklist

A PR allows others to review and discuss changes before merging into main.


๐Ÿ‘ฅ 5. Collaborating on Pull Requests

Others can:

Once approved, you or a maintainer can merge the branch into main.


๐Ÿ“ค 6. Pulling Latest Changes

Always keep your local repository up to date.

๐Ÿ”น From the main branch

git checkout main
git pull origin main

๐Ÿ”น If youโ€™re on a feature branch and want to update it with the latest main

git fetch origin
git rebase origin/main
# or
git merge origin/main

Use merge for safety in teams. Use rebase for a cleaner history if youโ€™re working solo.


๐Ÿงน Optional: Deleting a Branch After Merge

Once merged, clean up old branches:

๐Ÿ”น Locally

git branch -d feature/new-feature

๐Ÿ”น Remotely

git push origin --delete feature/new-feature

๐Ÿ“Œ Summary of Key Commands

Action Command
Clone repo git clone URL
Create & switch branch git checkout -b branch-name
Stage changes git add .
Commit changes git commit -m "Message"
Push branch git push origin branch-name
Pull latest changes git pull origin main
Merge main into branch git merge origin/main
Delete local branch git branch -d branch-name
Delete remote branch git push origin --delete branch-name

๐Ÿ› ๏ธ Pro Tips