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.
main
branchTo contribute to a project on GitHub, first clone the repository to your local machine.
git clone https://github.com/username/repo-name.git
cd repo-name
This creates a local copy of the remote GitHub repository.
Use branches to work on features or fixes without affecting the main
branch.
git checkout -b feature/new-feature
Branch names should be short, lowercase, and use hyphens (
-
) for readability.
After editing files:
git add .
git commit -m "Add new feature: description"
git push origin feature/new-feature
origin
refers to the GitHub repo. This command creates the remote branch if it doesnโt exist.
Go to your repository on GitHub. Youโll see an option to โCompare & pull request.โ
Closes #3
)A PR allows others to review and discuss changes before merging into
main
.
Others can:
Once approved, you or a maintainer can merge the branch into main
.
Always keep your local repository up to date.
main
branchgit checkout main
git pull origin main
main
git fetch origin
git rebase origin/main
# or
git merge origin/main
Use
merge
for safety in teams. Userebase
for a cleaner history if youโre working solo.
Once merged, clean up old branches:
git branch -d feature/new-feature
git push origin --delete feature/new-feature
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 |
feature/login-form
or bugfix/404-page
.Before pushing, always run:
git status
git log --oneline