user1899082
user1899082

Reputation:

Rename Git branch "Master" that conflicts with branch "master" in case-insensitive file system?

An intern has created a branch from our master branch and has named it Master! Now when I want to merge my code into the real master and do a git pull, I get an error like this:

error: Ref refs/remotes/origin/master is at bce957a261a1ef76eaec043243c5d036f8d5483e but expected afba8312e4c8bba8d3e6ba440463381dfe819461
From http://github.company.com/InternID/her_prototype
 ! afba831..db56ee6  master     -> origin/master  (unable to update local ref)

We are on OSX, which is case-insensitive to files names, so master and Master look the same to it.

My question

How can I rename this Master branch that the intern has created to something else?

Upvotes: 6

Views: 414

Answers (2)

number5
number5

Reputation: 16453

My solution is similar to @Carl's but simpler

The following steps will rename the Master branch to new_branch_name branch (make sure you do it in a case-sensitive system)

git checkout -t origin/Master
git checkout -b new_branch_name
git push origin new_branch_name:new_branch_name
git push origin :Master

Upvotes: 1

Carl Norum
Carl Norum

Reputation: 225262

I don't have a quick way to test, but something like:

git checkout master
git branch -m temp
git checkout --track origin/Master
git push origin HEAD:renamed
git push origin :Master
git checkout temp
git branch -D Master
git branch -m master

Should do it.

It might be easier to just make a case-sensitive disk image on your mac, clone to it, and do the fixes there.

Edit: I made a quick test and it worked as described above. There may be some shortcuts; I'll leave that to commenters to pull out. Here's a transcript (comments with # inline):

$ git remote update                                # update repository
Fetching origin
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
From /Volumes/Disk Image/remote
 * [new branch]      Master     -> origin/Master
$ git branch -a                                    # note bad name 'Master'
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/Master
  remotes/origin/master
$ git checkout master
Already on 'master'
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)
$ git branch -m temp                               # rename 'master' for a moment
$ git checkout --track origin/Master               # checkout the bad branch
Branch Master set up to track remote branch Master from origin.
Switched to a new branch 'Master'
$ git push origin HEAD:renamed                     # push it with a different name
Total 0 (delta 0), reused 0 (delta 0)
To /Volumes/Disk Image/remote
 * [new branch]      HEAD -> renamed
$ git push origin :Master                          # delete bad branch on remote
To /Volumes/Disk Image/remote
 - [deleted]         Master
$ git checkout temp                                # checkout renamed 'master'
Switched to branch 'temp'
$ git branch -D Master                             # delete bad local branch
Deleted branch Master (was 5343242).
$ git branch -m master                             # change 'master' name back
$ git branch -a                                    # presto!
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/renamed

Upvotes: 3

Related Questions