βœ“ Link copied to clipboard!

Git Push Rejected (error: failed to push some refs) Solution in Hindi: Complete Step-by-Step Fix

Aayush Kumar

Aayush Kumar

β€’ 5 min read
Git Push Rejected (error: failed to push some refs) Solution in Hindi: Complete Step-by-Step Fix

Jab bhi koi beginner developer ya software engineer Git aur GitHub sikhna shuru karta hai, to ek error lagbhag har kisi ko raat bhar pareshaan karta hai:

! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'github.com/username/repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.

Ye error screen par aate hi beginners darr jaate hain ki unka code delete ho gaya ya repo corrupt ho gayi. Par sach ye hai ki ye koi bug nahi haiβ€”ye Git ka ek protective security feature hai!

Iss comprehensive Hindi tutorial mein hum detail mein samjhenge ki ye error kyu aata hai aur bina ek bhi line code khoe isko professionally kaise solve kiya jata hai.


Error Ka Asli Kaaran (Root Cause) Kya Hai?

Git ek Distributed Version Control System hai. Iska matlab:

  1. Ek repo aapke local PC par hai (Local Repository).
  2. Ek repo GitHub ke server par hai (Remote Repository).

Sochiye GitHub par aapki repo mein commits hain: A -> B -> C. Aapke computer par commits hain: A -> B -> D.

GitHub ke paas Commit C hai jo aapke computer par maujood nahi hai! Aisa kab hota hai?

  • Aapne GitHub website par jaakar direct README.md ya koi file edit kar di.
  • Aapki team ke kisi doosre developer ne branch par naya code push kar diya.
  • Aapne GitHub par repo banate waqt β€œAdd a README file” ya β€œ.gitignore” tick kar diya tha, par local repo alag se git init ki thi.

Agar Git aapka push accept kar leta, to GitHub ka Commit C gayab ho jata! Isiliye Git kehta hai: β€œPehle GitHub ka latest code apne PC par laao (pull karo), sync karo, phir push karo.”


Method 1: The Clean Professional Way (git pull --rebase)

Professional developers hamesha rebase ka istemal karte hain taaki git commit history clean rahe.

Step-by-Step Commands:

1. Remote changes ko pull aur rebase karein:

git pull --rebase origin main

(Note: Agar aapki branch ka naam master hai, to main ki jagah master likhein).

2. Agar koi conflict nahi hai, to direct push karein:

git push origin main

Bas! Aapka code bina kisi jhanjhat ke GitHub par live upload ho jayega.


Method 2: Merge Conflict Aaye To Kaise Solve Karein?

Agar aapne aur kisi doosre developer ne same file ki same line ko edit kiya tha, to pull karne par terminal kahega: CONFLICT (content): Merge conflict in index.html

Iska solution bohot aasan hai:

  1. VS Code Editor kholein: Jis file mein conflict hai wo red ya highlight ho jayegi.
  2. File ke andar aapko aisi markings dikhengi:
    <<<<<<< HEAD (Current Change - Aapka code)
    <h1>Welcome to My Awesome Portfolio</h1>
    =======
    <h1>Welcome to Technical Dikhao Web App</h1>
    >>>>>>> 7d4a2b1 (Incoming Change - GitHub ka code)
  3. VS Code ke upar clickable buttons dikhenge:
    • Accept Current Change: Agar aapko apna likha hua code rakhna hai.
    • Accept Incoming Change: Agar GitHub wala code sahi hai.
    • Accept Both: Agar dono code chahiye.
  4. Correct code chunne ke baad file ko Save karein (Ctrl + S).
  5. Terminal mein ye 3 commands chalaein:
    git add .
    git rebase --continue
    git push origin main

Problem solve ho jayegi aur commits successfully push ho jayenge!


Method 3: Unrelated Histories Error Ka Solution

Agar aapko ye error mile: fatal: refusing to merge unrelated histories

Iska matlab local repo aur GitHub repo dono alag-alag roots se shuru hui hain. Isko bypass karne ke liye ye command use karein:

git pull origin main --allow-unrelated-histories

Iske baad enter dabayein, nano/vim editor khule to :wq type karke enter karein, aur phir:

git push origin main

Warning: git push --force Kab Use Karein Aur Kab Nahi?

Aapko YouTube par ya StackOverflow par log kahenge: β€œBhai git push -f origin main chala de, sab theek ho jayega!”

⚠️ Caution:

  • Kab Chala Sakte Hain: Agar repo 100% aapki personal hai, aap akele kaam kar rahe hain, aur GitHub ka puraana code aapko sach mein nahi chahiye.
  • Kab KABHI NAHI Chalana: Agar aap company mein hain ya college team project par hain. Force push chalate hi aapke doston ka code permanently delete ho jayega aur team repo crash ho jayegi!

Pro Developer Cheat Sheet

SituationBest Command
Normal sync updategit pull --rebase origin main
New branch pushgit push -u origin feature-branch
Check commit differencegit log --oneline --graph --all
Abort a bad merge/rebasegit rebase --abort ya git merge --abort


🌐 Authoritative Reference & Source: Adhik jankari aur official documentation ke liye aap Git-SCM Official Documentation ko visit kar sakte hain.

Ye article kaisa laga? Share karein:

Apne doston ki madad karein useful tech jankari share karke!

πŸš€

TechVerse VIP Community

Har roz nayi tech tips, hidden AI tools aur discount deals ke liye judein!

Bookmark TechVerse β˜…
Aayush Kumar

Aayush Kumar

Aayush Kumar TechVerse ke Founder aur Lead Technical Editor hain. Woh technology, software development, AI tools aur consumer gadgets par research-based content publish karte hain.

Lekhak ka poora profile aur sabhi articles dekhein β†’
πŸ“¬

Tech Updates Seedha Inbox Mein!

Har hafta latest AI news, coding tips, aur gadget reviews. Get weekly tech updates straight to your inbox.

βœ… No spam, sirf quality content. Kabhi bhi unsubscribe kar sakte ho.