Closed yalinli2 closed 3 years ago
Well I didn't receive any feedbacks, so I assume all is good and change the default branch name.
I've changed the default branch name to main, but you need to manually update your local environment. You should see instructions the first time you visit the repository homepage (this is my, yours might be upstream instead of origin if you are using fork):
git branch -m master main
git fetch origin
git branch -u origin/main main
However, this didn't work for me at all, upon fetching, I got an error:
fatal: couldn't find remote ref refs/heads/master
Took me some time to figure out, still not sure why the official method didn't work, but here's what ultimately helped me:
First used git remote show origin
, there was a stale master branch:
* remote origin
Fetch URL: https://github.com/QSD-Group/QSDsan.git
Push URL: https://github.com/QSD-Group/QSDsan.git
HEAD branch: main
Remote branch:
refs/remotes/origin/master stale (use 'git remote prune' to remove)
Local branches configured for 'git pull':
beta merges with remote beta
main merges with remote master
Local refs configured for 'git push':
beta pushes to beta (up to date)
main pushes to main (up to date)
Then prune it, used the dry-run
flag for cautious purpose:
git remote prune origin --dry-run
Git warned that my head will become dangling,
Pruning origin
URL: https://github.com/QSD-Group/QSDsan.git
* [would prune] origin/master
refs/remotes/origin/HEAD will become dangling!
I pruned it anyway (git remote prune origin
), as suggested in the post above, I can fix this
And I tried git remote set-head origin -a
, but git threw me an error:
error: Not a valid ref: refs/remotes/origin/main
origin/HEAD set to main
And master
was still in git remote show origin
:
* remote origin
Fetch URL: https://github.com/QSD-Group/QSDsan.git
Push URL: https://github.com/QSD-Group/QSDsan.git
HEAD branch: main
Local branches configured for 'git pull':
beta merges with remote beta
main merges with remote master
Local refs configured for 'git push':
beta pushes to beta (up to date)
main pushes to main (up to date)
But when git checkout main
, finally I got a prompt:
Switched to branch 'main'
Your branch is based on 'origin/master', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
After git branch --unset-upstream
, now everything is normal
git remote show origin
* remote origin
Fetch URL: https://github.com/QSD-Group/QSDsan.git
Push URL: https://github.com/QSD-Group/QSDsan.git
HEAD branch: main
Local branch configured for 'git pull':
beta merges with remote beta
Local refs configured for 'git push':
beta pushes to beta (up to date)
main pushes to main (up to date)
Yay! 🎉
Because of the historical origin of the branch (see the thread, and salient examples of master NOT being used in the "master copy" way), I think it'll be good to rename the default branch following the broad movement, including Git.
I'm opening this issue here for any comments, and will execute it in the following month or so following the renaming guidance if folks see so problem, thanks!