"GitHub Demystified: Clone, Push, Pull, Fork & Branching Strategies (The Right Way)"


In this part, we dive into how GitHub works in real-world collaboration β starting from cloning a repository using HTTPS or SSH, to pushing your changes, pulling updates, forking repositories, and using Personal Access Tokens (PAT) and SSH keys securely.
We also explore branching strategies, including GitFlow, and touch briefly on rebase, a powerful tool to maintain a clean commit history.
𧬠How to Clone a Repository
There are two primary methods to clone a GitHub repository to your local machine:
π 1. HTTPS (Beginner-Friendly)
Steps:
Go to a GitHub repository.
Click the Code button β Copy the HTTPS link.
Use the terminal:
git clone https://github.com/username/repo-name.git
β No setup required, works out of the box
ποΈ 2. SSH (Advanced & Secure)
Steps:
Set up your SSH keys with GitHub.
Then use:
git clone git@github.com:username/repo-name.git
π More secure, no password needed every time, but requires initial setup.
π€ Git Push β Send Your Code to GitHub
After writing code and committing changes, you can push to your remote branch:
git add .
git commit -m "Your message"
git push origin <branch-name>
π Two Secure Ways to Push:
π PAT (Personal Access Token)
A GitHub-generated token used in place of your GitHub password for HTTPS pushes.π SSH Key
A cryptographic key pair that allows secure authentication without typing your password repeatedly.1. GitHub PAT (Personal Access Token) Method
PAT is used for HTTPS-based Git operations (e.g.,
git clone
,git push
) instead of passwords.Steps to Create & Use a GitHub PAT:
A. Generate a PAT in GitHub:
Go to GitHub β Settings β Developer Settings β Personal Access Tokens (PAT).
Click Generate new token.
Give it a name (e.g., "MyLaptop").
Set expiration (recommended: 30-90 days).
Select scopes (permissions):
For repo access:
repo
(full control of private repos)For workflows:
workflow
For deleting repos:
delete_repo
(For most users,
repo
is enough)
Click Generate Token.
Copy the token (it will only be shown once!).
B. Use PAT in Git Commands:
Clone a repo:
git clone https://github.com/username/repo.git
- When prompted for a password, paste the PAT.
Set PAT as Git Credential Helper (to avoid re-entering):
git config --global credential.helper store
- Next time you push/pull, Git will save the PAT.
2. GitHub SSH Method
SSH provides secure authentication using cryptographic keys instead of passwords or tokens.
Steps to Set Up SSH for GitHub:
A. Generate an SSH Key Pair:
Open Terminal (Linux/macOS) / Git Bash (Windows).
Run:
ssh-keygen -t ed25519 -C "your_email@example.com"
- (Or use
-t rsa -b 4096
for older systems)
- (Or use
Press Enter to save in
~/.ssh/id_ed25519
.Set a passphrase (optional but recommended for security).
B. Add SSH Key to GitHub:
Copy the public key (
id_
ed25519.pub
):cat ~/.ssh/id_ed25519.pub
Go to GitHub β Settings β SSH and GPG Keys.
Click New SSH Key.
Paste the public key and save.
C. Test SSH Connection:
ssh -T git@github.com
If successful, you'll see:
Hi username! You've successfully authenticated...
D. Use SSH for Git Operations:
Clone a repo:
git clone git@github.com:username/repo.git
Change existing HTTPS repo to SSH:
git remote set-url origin git@github.com:username/repo.git
Comparison: PAT vs. SSH in GitHub
Feature | PAT (HTTPS) | SSH |
Authentication | Token-based | Key-based |
Security | Less secure if leaked | More secure (key + passphrase) |
Usage | Required for HTTPS Git operations | Required for SSH Git operations |
Expiration | Yes (configurable) | No (but keys can be revoked) |
Best For | CI/CD, scripts, temporary access | Developers, long-term access |
Which One Should You Use?
Use PAT if:
You're using HTTPS Git.
You need API access (e.g., GitHub API calls).
You're working in CI/CD pipelines (e.g., GitHub Actions).
Use SSH if:
You prefer password-less secure access.
You frequently push/pull code.
You want long-term authentication.
Would you like help troubleshooting any specific step? π
π₯ Git Pull β Get the Latest Changes
To sync your local repo with GitHub:
git pull origin <branch-name>
π₯ This merges the latest changes from the remote branch into your local branch.
π΄ Fork β Create Your Own Version of a Repository
Forking is common in open-source contribution.
Click Fork on any GitHub repository.
It creates a copy in your GitHub account.
Useful when you donβt have write access to the original repository.
Useful for contributing to open-source projects
π Git Fetch β Stay Up-to-Date (Without Merging)
Use git fetch
to download changes from the remote repo without affecting your working code:
git fetch
π Youβll see the updates, but you decide when to merge them.
π§ Branching Strategies β From Chaos to Clarity
π« Strategy 1: Random Naming
Developers use inconsistent, personal names for branches like final_fix
, my_feature
, or new_try
.
β Hard to track, prone to confusion and duplication.
β οΈ Strategy 2: Isolated Hotfixes
Hotfixes are made without syncing back to the main development line. Developers may miss updates.
π§ Risk: Fixes might not be merged back properly, causing regression later.
β Strategy 3: Professional Workflow (Agile) Recommended)
Developers work using ticket systems like JIRA.
Time-bound sprints (e.g., 7 days per task).
This is called the Agile Development Process.
GitFlow introduces a structured, team-friendly approach to branching.
π One-Line Overview of GitFlow Branches:
π GitFlow Branches Explained
π
main
/master
β Holds the production-ready code.
β Every commit here is a stable release deployed to users.π
develop
β The integration branch where all new features and bugfixes are combined.
π Prepares code before moving to production.Supported Branch :
π±
feature/*
β For new features or tasks.
π§ͺ Branched fromdevelop
, and merged back once the feature is complete.π
release/*
β Created to prepare a new version for production.
π§Ό Only final bug fixes, version bumps, and polishing happen here.π₯
hotfix/*
β For urgent fixes in production.
β Branched frommain
, then merged into bothmain
anddevelop
.
π Git Rebase β Clean Up Your History (One-Liner)
git rebase
lets you move or combine commits to a new base commit β making your Git history linear and clean.
π§ Final Thoughts
Understanding how GitHub works with cloning, pushing, forking, and branching makes you a better collaborator and developer. In teams, choosing the right branching strategy β like GitFlow β ensures clean releases, organized development, and smooth hotfix handling.
Subscribe to my newsletter
Read articles from ABHISHEK WAGHMARE directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

ABHISHEK WAGHMARE
ABHISHEK WAGHMARE
An IntroductionβTo DevOps: Where Development And Operations Meet π My DevOps learner journey has been inspired by a true passion for continual personal development and a genuine curiosity forβcloud and automation technologies. With the practice of engaging in numerous online coursework and community threads, I have built a growing comprehension of what is necessary for everyday life in the toolsβoffered from Docker, Jenkins, and Kubernetes, which are mandatories in the IT Society. π What sets me apart? A commitment to practical application. Through personal projects, I actively implement my learning to solve real-world problems, gaining hands-on experience. This proactive approach helps me not only understand technologies at a surface level but to deeply integrate them into effective solutions. My ultimate goal? To merge innovative DevOps practices with business objectives to streamline operations and boost productivity in any tech landscape. I am eager to bring my fresh perspective and evolving expertise to a vibrant team, where continuous learning is intertwined with company growth. π¨ Letβs connect and explore how we can drive progress together in the fascinating world of DevOps!