Rename Git branch "Master", which conflicts with the branch "master" in the file system case-insensitive?

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

 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 not case sensitive, so master and master look the same for it.

My question

How can I rename this master branch that the intern created for something else?

+6
source share
2 answers

I don't have a quick 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 

Must do it.

Perhaps it would be easier to just create a case-sensitive disk image on your Mac, clone it and make corrections there.

Edit: I did a quick test and it worked as described above. There may be some shortcuts; I will leave it to commentators to break free. Here's the transcript (comments from # 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 
+3
source

My solution is similar to @Carl, but simpler

The following steps will rename the Master branch to the new_branch_name branch (make sure that you execute it on the system case-sensitive )

 git checkout -t origin/Master git checkout -b new_branch_name git push origin new_branch_name:new_branch_name git push origin :Master 
+1
source

Source: https://habr.com/ru/post/952164/


All Articles