DjangoGirls / tutorial

This is a tutorial we are using for Django Girls workshops
http://tutorial.djangogirls.org/
Other
1.53k stars 1.86k forks source link

Git branch rename is allowed until a commit exists #1779

Closed ekohl closed 11 months ago

ekohl commented 1 year ago

Issue description

On https://tutorial.djangogirls.org/en/deploy/ it tells the reader to rename the branch to main if it's master (for git < 2.28). However, you can only rename it after something has been committed.

Language

It was in English, but probably applies to all.

Operating system

Mac OS X.

das-g commented 1 year ago
git branch -M <new branch name>

works for me on a fresh repo without any commits. But then again, I've now got Git version 2.38.1, so maybe in (some of) the versions where the default branch name is still master it didn't yet work?

(I'm on Linux, but I don't think that the OS should make a difference regarding this.)

ekohl commented 1 year ago

My student was running Mac OS X with git 2.15 and I can confirm she couldn't rename. It may very well be that a modern git can do this.

nikhiljohn10 commented 1 year ago

In this link, we can find another command: git config --global --add init.defaultBranch main, which could work instead for older versions. So it would be a one-time thing and never had to rename the branch.

ekohl commented 1 year ago

IMHO renaming master to main is not going to matter at all so I'd suggest removing it. Just change the push command to git push --set-upstream origin HEAD and it'll use whatever branch you're on. AFAIK GitHub is smart enough to set the default branch to it so a clone from some other place will also just work.

thibaudcolas commented 11 months ago

Just confirming this is still a problem. We’re running git inside the RunCode environment suggested by the tutorial, with Ubuntu 20.04.5 LTS, and git 2.25.1. The error message is:

error: refname refs/heads/master not found
fatal: Branch rename failed

The solution is very simple – either: