5 min read
Github Full Basics & Practical Guide
This guide covers GitHub only (remote repositories, collaboration, organizations, PRs, permissions, .gitignore, README best practices). It assumes you already know Git basics (init, add, commit, branches, merge, rebase).
Why Github?
GitHub is a cloud platform for hosting Git repositories and enabling collaboration.
Use cases:
-
Personal storage: Keep your projects backed up online and accessible from anywhere.
-
Multi-developer collaboration: Multiple developers can work on the same codebase.
-
Contributions & open-source: Contribute to public projects, submit fixes and features.
-
Code review: Pull Requests enable discussion and review before merging.
-
Issues & project management: Track bugs, features, and tasks.
-
CI/CD integrations: Automate testing and deployments.
Github Repositories (remote)
Create a New Repo Locally and Connect to Github
echo "# git_playground" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/USERNAME/git_playground.git
git push -u origin mainConnect an Existing Local Repo to Github
git remote add origin https://github.com/USERNAME/git_playground.git
git branch -M main
git push -u origin mainExplanation
git branch -M main-Mforcefully renames the current branch to main (instead ofmasteror any other name).
git remote add origin https://github.com/USERNAME/repo.git-
remote: connect your local repo to a remote repo on GitHub. -
origin: a shortcut name for the remote URL (you can name it anything, butoriginis the convention).
git push -u origin main-
push: upload your commits to GitHub. -
origin: remote name (URL shortcut). -
main: target branch on GitHub. -
-u(upstream): sets the default remote/branch so next time you can usegit pushonly.
Authentication & Common Error (403)
You might see:
remote: Permission to USER/repo.git denied.
fatal: unable to access 'https://github.com/USER/repo.git/': 403Why this happens:
-
You’re not authenticated.
-
You don’t have permission on that repo.
-
You’re using HTTPS without a Personal Access Token (PAT).
Fix (Recommended):
-
Use GitHub Personal Access Token (PAT) instead of password.
-
Or use SSH keys and push via SSH URL:
git remote set-url origin git@github.com:USERNAME/repo.gitRemote Branches & Tracking
List all branches (local + remote-tracking):
git branch -aList remote-tracking branches only:
git branch -rFetch vs Pull
git fetch origin-
Updates remote-tracking branches only.
-
Does not change your local working branch.
git pull origin main-
pull=fetch+merge -
Updates your local branch with remote changes.
Deleting Remote Branches
Delete locally:
git branch -D branchnameDelete on GitHub (remote):
git push origin --delete branchnameNote:
--deleteremoves the branch from the remote repository.
Cloning a Repository
git clone https://github.com/USERNAME/repo.gitThis downloads the repo and automatically sets:
-
originremote -
default upstream branch
Fork & Pull Request (pr)
Fork
-
A fork is your personal copy of someone else’s repository on your GitHub account.
-
Used when you don’t have write access to the original repo.
Typical Fork Workflow
-
Fork the repo on GitHub.
-
Clone your fork:
git clone https://github.com/YOUR_USERNAME/repo.git- Add upstream (original repo):
git remote add upstream https://github.com/ORIGINAL_OWNER/repo.git- Create a feature branch:
git switch -c feature-x- Push changes to your fork:
git push origin feature-x- Open a Pull Request from your fork → original repo.
Pull Request (pr)
-
A PR is a request to merge your changes into another branch/repo.
-
Enables:
-
Code review
-
Discussion
-
CI checks before merge
-
Github Organizations
Organizations are used to manage teams, permissions, and repositories for companies, teams, or communities.
Benefits
-
Centralized repo ownership
-
Role-based access control
-
Teams for managing permissions
-
Better security & auditing
-
Scales well for large teams
Roles & Permissions
Members
-
Part of the organization.
-
Can be assigned to teams.
-
Permissions depend on team/repo access.
Outside Collaborators
-
Not organization members.
-
Granted access to specific repositories only.
-
Useful for contractors or external contributors.
Teams
-
Group members into teams (e.g., Backend, Frontend, DevOps).
-
Assign permissions to teams instead of individuals:
-
Read: view code
-
Triage: manage issues/PRs
-
Write: push to repo
-
Maintain: manage repo settings (limited)
-
Admin: full control
-
Permissions Scope
Permissions can be applied at:
-
Organization level
-
Team level
-
Repository level
This gives fine-grained control over:
-
Who can push
-
Who can review
-
Who can manage settings
.gitignore (secrets & Private Files)
Use .gitignore to prevent sensitive or unnecessary files from being pushed:
Examples:
-
API keys
-
Secret tokens
-
Environment files
-
Build artifacts
-
IDE configs
Example .gitignore:
.env
*.key
*.pem
node_modules/
build/
dist/⚠ Never push secrets to GitHub. If you did, rotate the key immediately.
Readme Files on Github
Repository Readme
-
Explains:
-
What the project does
-
How to install
-
How to run
-
How to contribute
-
License
-
Github Profile Readme
Create a repo named exactly like your username:
USERNAME/USERNAMEYour README.md will appear on your GitHub profile.
You can use profile README generators to quickly scaffold sections like bio, skills, stats, badges, and featured projects.
Best Practices
-
Use SSH or PAT for authentication
-
Protect
mainbranch (require PRs) -
Use meaningful PR titles & descriptions
-
Review code before merging
-
Keep secrets out of repos
-
Use Issues for tracking work
Summary
-
GitHub is for hosting, collaboration, and code review.
-
Use push/pull/fetch to sync with remote.
-
Use fork + PR when you don’t have write access.
-
Use organizations & teams for scalable permission management.
-
Protect secrets with .gitignore.
-
Write a clear README for every repo.
End of GitHub Guide 🚀
Comments
Loading the discussion…