Completely replace remote branch with another in github leaving no traces of the old one

I pushed a branch to an empty github repo :

MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHubSquash)
$ git remote add github  https://github.com/Utumno/ted2012.git
MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHubSquash)
$ git push -u github GitHubSquash
Username for 'https://github.com': Utumno
Password for 'https://Utumno@github.com':
//...
To https://github.com/Utumno/ted2012.git
 * [new branch]      GitHubSquash -> GitHubSquash
Branch GitHubSquash set up to track remote branch GitHubSquash from github.

Then I noticed I had pushed some fluff along and tried to delete the branch/replace it with another etc. I failed :

  • Cannot clone/commit git repository through gitolite/Redmine
  • How to ignore folder in GitHub correctly?
  • Git: File Rename
  • git-p4 migrate branches in different subdirectories
  • Verify changes in git modules
  • View a file in a different Git branch without changing branches
  • MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHub2)
    $ git push  :github && git push github GitHub2
    ssh: connect to host  port 22: Bad file number
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHub2)
    $ git checkout GitHubSquash
    Switched to branch 'GitHubSquash'
    Your branch is ahead of 'github/GitHubSquash' by 1 commit.
      (use "git push" to publish your local commits)
    MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHubSquash)
    $ git push  :github
    ssh: connect to host  port 22: Bad file number
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHubSquash)
    $ git push  -u :github
    ssh: connect to host  port 22: Bad file number
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    

    I had to delete the repo and push my new branch anew. That worked but left me wondering :

    1. What should I have done to completely replace the remote branch with
      another ?

    2. Why on earth I was getting the ssh: connect to host port
      22: Bad file number
      errors – while my first push succeeded (and notice I am on http) ?

      $ git --version
      git version 1.8.1.msysgit.1
      

  • HG: Match remote repo's changesets
  • What does !*/ mean in .gitignore
  • Why do I get “error: failed to push some refs” when pushing to Heroku?
  • Why does git-pull manpage say “You never do your own development on branches that appear on the right hand side of a <refspec> colon on Pull: lines”?
  • What does “Auto packing the repository for optimum performance” mean?
  • No module named ib.message
  • 2 Solutions collect form web for “Completely replace remote branch with another in github leaving no traces of the old one”

    Your syntax is wrong. The correct command is:

    git push -f github GitHubSquash
    

    This will replace the remote GitHubSquash branch with your local version. If you just want to delete the remote branch:

    git push -f github :GitHubSquash
    

    I guess you got your error, because git is trying to interpret :github as an url and weird stuff happens :).

    git push origin :GitHubSquash
    

    to delete remote branch

    git push --set-upstream origin GitHubSquash
    

    to push local branch

    Git Baby is a git and github fan, let's start git clone.