Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7488851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:05:54+00:00 2026-05-29T15:05:54+00:00

On a git/github project I am working on a branch. Upon a push, it

  • 0

On a git/github project I am working on a branch. Upon a push, it said the following:

git push
To git@github.com:...
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:...'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

I tried to fix this problem and upon Googleing I came up with this line:

git push --mirror

I issued the following command and now it seems that I have deleted a lot of branches from the server.

Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:...
 - [deleted]         develop
 + 797beee...bafbc50 master -> master (forced update)
 - [deleted]         milestone
 - [deleted]         robot
 - [deleted]         strategy
 * [new branch]      origin/HEAD -> origin/HEAD
 * [new branch]      origin/develop -> origin/develop
 * [new branch]      origin/master -> origin/master
 * [new branch]      origin/milestone -> origin/milestone
 * [new branch]      origin/robot -> origin/robot
 * [new branch]      origin/robot_simulator -> origin/robot_simulator
 * [new branch]      origin/strategy -> origin/strategy
 * [new branch]      origin/vision -> origin/vision

Can you tell me what has happened and how can I undo the change I made? (in case I deleted those branches)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:05:55+00:00Added an answer on May 29, 2026 at 3:05 pm

    You pushed to the default push target, git@github.com. This means, that git@github.com was a remote in you source repo.

    That implies, that the refs deleted from the server would still be in the remote locally after the push. Do not update the remotes (!).

    Verify this by doing

    git branch -a
    

    on the side you pushed from (local).

    It will probably show the refs that were deleted from the remote server.

    [to be continued]

    You could do something like:

    for-each-ref refs/remotes/origin | while read sha type name
    do 
        git branch "rescue_$(basename "$name")" "$sha"
    done
    

    to recover the branches locally. They will be named prefixed with rescue_ just as a precaution (in case you get funny or conflicting ref names).

    Replace origin with the name of your remote


    Test script

    In case you want to test the procedure in a controlled environment, here is my approach condensed to minimum steps (execute in an empty dir, e.g. /tmp/work)

    git init A; (cd A; touch test; git add test; git commit -m initial; git branch test1; git branch test2; git branch test3)
    git clone A B
    (cd B; git push --mirror origin; git branch -a)
    cd A
    git for-each-ref refs/remotes/origin | while read sha type name; do git branch "rescue_$(basename "$name")" "$sha"; done
    git branch -a
    

    Note how in this version, I cd into A – which would be your github repo. You could git clone --mirror git@github.com:... local_rescue in order to get a suitable local version of that.

    I recommend you play around getting to terms with the procedure before trying it out. It never hurts to backup your repositories along the way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a git repository (at github.com) with two branches: master and gh-pages. I
I added some Haml templates to my Rails 3 project with git clone git://github.com/psynix/rails3_haml_scaffold_generator.git
I started some project on github.com. And I'm working on two machines. I did
I've been trying to install Shoulda script/plugin install git://github.com/thoughtbot/shoulda.git but all I get is:
What will be proper regular expression for git repositories? example link: git@github.com:someone/someproject.git so it
I have tryed to run this code in my console: script/plugin install git://github.com/apotonick/cells.git ...but
Github has the following recommendation for global git configuration ~/.gitconfig : [alias] # Is
I have a project hosted on github. There is a main branch (main-branch) for
I am working on a project and I created a repository with a master
I am working on a github hosted project. For testing reasons, I have to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.