2

I'm quite sure this question has been asked before but I dont seem to find it. So sorry if it is a dublicate.

I have a bare repository lets call it project_x.git, if we check the config file it says

[core]
repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly

so it bare for sure right, bare=true. Now I'm trying to replace master with a cleanup version.

$ git push origin :master
remote: Updating references: 100% (1/1)
To http://gitrepo.local/git/project_x.git
! [remote rejected] master (branch is currently checked out)
error: failed to push some refs to 'http://gitrepo.local/git/project_x.git'

I'm using gitblit btw, and that is not the actual server url.

This response puzzels me, how can I have a checkout branch on my bare repo? Who is working on that branch :), Makes no sense. Either it is not bare some how config wise or gitblit is messing with me. I dont understand?

What is wrong?

btw same message if I try

git push -f , 

Edit: this works but you can not delete the branch as I tried earlier.

Thanks

User123456
  • 671
  • 2
  • 9
  • 19

2 Answers2

6

There is a HEAD set on the bare repo, which actually points to the branch which is checked out when you run git clone <url> without arguments.

As far as I know you can't delete the remote HEAD branch, so if you want to delete the master you have to push a second branch, move your HEAD to that branch, then push an empty branch in master:

locally:

git branch mybranch
git push origin mybranch

on the bare-repo:

git symbolic-ref HEAD refs/heads/mybranch

locally:

git push origin :master

Of course you can then push another branch you call master if you want, and move the HEAD back to it.

git push origin newbranch:master
git symbolic-ref HEAD refs/heads/master #(on bare repo)
Sébastien Dawans
  • 4,537
  • 1
  • 20
  • 29
  • great explanation, I never had to do such violent act on my remote server but maven release was clottering it down with maven-release commits, after an interactive rebase I discovred this problem when trying to rewrite history. Anyhow, I'm back on track thanks to you. – User123456 Mar 01 '13 at 13:01
0

Seems like your local repository was/is tracking the remote origin/master branch. And you have local master checked out.

git push origin :master

... means you are deleting the remote tracking branch, but that fails when you have the same checked out locally. I think you would have to have another local branch checked out to delete a remote branch.

If you want to "start over" with the remote bare repository, i would just do (on the remote repo) a new

git init --bare

... and then push your local master to that, and then set it as the upstream.

git push origin master -u
Raul Nohea Goodness
  • 2,549
  • 23
  • 24
  • Actually I was on my cleanup branch when I got this rejection from remote. I know the bare commands that's how I created my bare repo in first place. I think you can delete remote even if you are on a tracking branch locally... I will try that and let you know. Thanks – User123456 Mar 01 '13 at 13:06