Menu

Fix "git push rejected (fetch first)" without losing work
📰

Fix "git push rejected (fetch first)" without losing work

DEV Community: github·Jey Singh·27 minutes ago
#rlWm9BK3
#devtogithub#technology#devto#dev#push
Reading 0:00
15s threshold

Git refused your push because GitHub has commits you don't have yet. Nothing is broken and nothing is lost. Get their work first, then push again.

The error

You run git push and see something like this:

! [ rejected ] main - > main ( fetch first ) error: failed to push some refs to 'github.com:you/shop-app.git' hint: Updates were rejected because the remote contains work that you do not hint: have locally. This is usually caused by another repository pushing to hint: the same ref.

Enter fullscreen mode

Exit fullscreen mode

If you already fetched their commits but have not merged them, Git says (non-fast-forward) and “the tip of your current branch is behind its remote counterpart” instead. The cause and the fix are the same.

What it means

Someone pushed to the same branch after you last pulled. It might be a teammate, or you on another computer, or an edit you made in the GitHub website. GitHub will not let your push replace commits you have never seen, because that would delete their work.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.