Paul
Paul

Reputation: 620

How to change my local Git branch name to uppercase

I created a branch from my master (origin) and called it TEST-101 (uppercase). I then worked on my branch and committed and pushed my changes up to origin. When I log in to Github, I can see I the branch I created.

I used git bash and checked out my local version of the branch, but I entered it in all lowercase: test-101. I then used Git Gui and committed my changes to the branch which was typed in lower case, and when I tried to push these changes it gave me an error:

POST git-receive-pack (390618 bytes)
remote: error: failed to lock refs/heads/test-101
Pushing to ht://example/example/example/example.git
To ht://example/example/example/example.git
! [remote rejected] test-101 -> test-101 (failed to lock)
error: failed to push some refs to 'http://example/example/example/example.git'

(Please note that I have changed some private info in the error.)

I have done some reading, and it appears that my local branch being in lowercase and the remote branch being in uppercase may be causing an issue?

Upvotes: 5

Views: 7038

Answers (4)

Paul
Paul

Reputation: 620

The following solved the problem:

git branch -m test-101 tmp_branch
git branch -m tmp_branch TEST-101

Upvotes: 9

Pockets
Pockets

Reputation: 1264

For anyone who comes across this in the future (like me) and finds that this does not work:

git branch -m branch_name tmp
git branch -m tmp BRANCH_NAME

you most likely have slashes in your branch name, e.g. BRANCH/NAME; if this is indeed the case, you will need to do something like the following (from the root directory of the repo):

git branch -m branch/name tmp
mv .git/refs/heads/branch .git/refs/heads/BRANCH
git branch -m tmp BRANCH/NAME

In the meantime I've submitted this to the Git mailing list and am waiting on responses.

Upvotes: 2

Surya
Surya

Reputation: 16002

You can do the following:

git branch -m test-101 tmp_branch
git checkout tmp_branch
git merge TEST-101 // make sure your data is up to date
git branch -D TEST-101
git branch -m tmp_branch TEST-101

-m option renames the branch, and -D option will delete the branch.

Upvotes: 4

Thomas Foster
Thomas Foster

Reputation: 321

Renaming the local branch to match the name of the remote branch (exactly, including capitalization) will resolve this, but you can also just git push explicitly specifying local and remote branches:

git push test-101:TEST-101

Upvotes: 0

Related Questions