Reputation: 6327
Our team is using Git for Windows and Git Extensions with GitHub as the remote repository. People have created branches with inconsistent capitalisation, which has caused some problems when two people have different names (differing only by case) for the same branch.
We'd like to standardise on using lowercase for all branch names to avoid this problem, but how do we convert all existing branch names to lowercase? There are many branches, both local and remote and some have pull requests outstanding. I only really care about "active" branches, i.e. those from which people will push again.
I tried the steps listed on https://gist.github.com/lttlrck/9628955, but ran into some problems. First, I can't rename "BranchName" directly to "branchname" in Windows, but OK, this can be worked around with a temporary name.
The more serious issue is that we have "folder names" in branches, e.g. "Test/RenameTest". When I rename the local branch to "test/renametest" it appears to work, but then pushing it fails with fatal: test/renametest cannot be resolved to branch.
I think this is because I have other branches named "Test/Whatever", so the "folder name" is still "Test", not "test". Having to manually rename every branch ever checked out on every machine is a daunting prospect. I'm hoping there is a better solution.
Upvotes: 2
Views: 2291
Reputation: 5517
You can create a remote branch based on another remote branch in one step:
git push origin origin/PATH/TO/MY_BRANCH:refs/heads/path/to/my_branch
Note the syntax:
git push [remote] [REF]:refs/heads/[BRANCH]
And since origin/PATH/TO/MY_BRANCH
is a valid ref, it can be used for the git push
command.
Then just delete the incorrectly named remote branch, like so:
git push --delete origin PATH/TO/MY_BRANCH
If your Windows Git Bash terminal has grep
and sed
and cut
commands available you can probably do it all at once. Start with something like this, and once it looks good, pipe its output into its own shell script (e.g., sh script_below.sh > my_big_git_rename.sh
), and then run that!
#!/bin/sh
git branch --remotes | # list all remote branches
grep '[A-Z]' | # only list branches with upper-case in their name
cut -b 10- | # cut first 10 chars (assumes remote named 'origin')
# build "git push" command:
sed 's/\(^.*$\)/git push origin origin\/\1:refs\/heads\/\1/' |
sed 's/:\(.*\)/:\L\1/' # lower-case the branch name
Upvotes: 2