++added: Renaming a branch --------- This needs some rationale and justification because during normal operation we never want to rewind a branch. It causes problems for anyone who has pulled from the branch. Normally branches only move forward. But sometimes renaming a branch is the best solution to a problem.
Sometimes a user has munged a commit, has pushed the desired branch onto a temporary branch (call it new-master), and wishes to have the new temporary branch become the master branch as the correction. Verify the current and future state of the repository:: GIT_DIR=/srv/git/exampleproject.git git branch GIT_DIR=/srv/git/exampleproject.git git log GIT_DIR=/srv/git/exampleproject.git git log new-master Save the current branch for a for backup:: GIT_DIR=/srv/git/exampleproject.git git branch -m master master-broken Move the new branch into place as master:: GIT_DIR=/srv/git/exampleproject.git git branch -m new-master master At this time the "current" branch will be shown to be master-broken:: GIT_DIR=/srv/git/exampleproject.git git branch master * master-broken (There is likely a less heavy-handed command to do this. This is the only way I know how at this moment.) Since this is a raw repository update the HEAD file directly:: echo ref: refs/heads/master > /srv/git/exampleproject.git/HEAD Verify the current status us as desired:: GIT_DIR=/srv/git/exampleproject.git git branch * master master-broken Verify that the change is correct. Better to leave the broken branch around for a while than to remove it too soon and lose something that should not have been lost. Then clean up and discard the broken branch:: GIT_DIR=/srv/git/exampleproject.git git branch -D master-broken -- forwarded from http://savannah.gnu.org/maintenance/Git#[email protected]/maintenance
