Saturday, November 22, 2025

Why Git Shows master but GitHub/GitLab Use main

Introduction

If you’ve ever run git init locally and noticed the default branch is master, but then created a repository on GitHub or GitLab and saw the default branch is main, you’re not alone. This difference often confuses developers, especially those new to Git. Let’s break down why this happens, what it means, and how you can align your workflow.


🌍 A Bit of History

  • Git’s original default branch: When Git was first created, the default branch name was master.
  • Shift to main: Around 2020, platforms like GitHub and GitLab changed their defaults to main to encourage more inclusive naming practices.
  • Result: Local Git (depending on your version) may still default to master, while hosted platforms default to main.

⚙️ What Happens in Practice

  • Running git init on older Git versions → creates master.
  • Creating a repo on GitHub/GitLab → starts with main.
  • When you push your local repo to GitHub/GitLab, you may end up with mismatched branch names unless you rename.

✅ How to Fix It

You have three main options:

  • Set main as the default globally

    git config --global init.defaultBranch main
    

    This ensures all new repos start with main.

  • Rename an existing branch

    git branch -m master main  
  • git pull origin main --allow-unrelated-histories
  • git push -u origin main
  • git push origin --delete master   # optional
    
  • Adjust per project
    If your team still uses master, you can keep it. GitHub/GitLab let you change the default branch in repo settings.


🚀 Best Practice

For modern projects, it’s best to standardize on main. This avoids confusion when collaborating, matches GitHub/GitLab defaults, and keeps your workflow consistent.

Conclusion

The difference between master and main isn’t a bug — it’s a reflection of Git’s history and evolving practices. By configuring your local Git to use main, you’ll save yourself and your team from branch name mismatches.

No comments:

Post a Comment

How to work with Meta‑Repository in GIT

Output looks like below: We are grouping multiple git repository under single git repository using SubModules concept. Each submodule is a g...