"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:

      1. Go to GitHub β†’ Settings β†’ Developer Settings β†’ Personal Access Tokens (PAT).

        1. Click Generate new token.

        2. Give it a name (e.g., "MyLaptop").

        3. Set expiration (recommended: 30-90 days).

        4. 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)

        5. Click Generate Token.

        6. 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:

  1. Open Terminal (Linux/macOS) / Git Bash (Windows).

  2. Run:

     ssh-keygen -t ed25519 -C "your_email@example.com"
    
    • (Or use -t rsa -b 4096 for older systems)
  3. Press Enter to save in ~/.ssh/id_ed25519.

  4. Set a passphrase (optional but recommended for security).

B. Add SSH Key to GitHub:

  1. Copy the public key (id_ed25519.pub):

     cat ~/.ssh/id_ed25519.pub
    
  2. Go to GitHub β†’ Settings β†’ SSH and GPG Keys.

  3. Click New SSH Key.

  4. 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

FeaturePAT (HTTPS)SSH
AuthenticationToken-basedKey-based
SecurityLess secure if leakedMore secure (key + passphrase)
UsageRequired for HTTPS Git operationsRequired for SSH Git operations
ExpirationYes (configurable)No (but keys can be revoked)
Best ForCI/CD, scripts, temporary accessDevelopers, 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.


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 from develop, 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 from main, then merged into both main and develop.

πŸ” 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.

1
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!