Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practices to switch from master to main #761

Closed
samteplitzky opened this issue Oct 6, 2020 · 11 comments
Closed

Best practices to switch from master to main #761

samteplitzky opened this issue Oct 6, 2020 · 11 comments

Comments

@samteplitzky
Copy link

As Github is switching its terminology from master to main (https://github.com/github/renaming) over the next several months, I'm curious what the Carpentries approach will be. In this lesson, there are several episodes (7, 8, 9 on quick glance) that would require quick changes from "master" to "main." Is this a current consideration?

@zingale
Copy link
Contributor

zingale commented Oct 11, 2020

I just taught the git lessons today, and indeed, when you create the github repo, it now defaults to main, and the instructions for pushing your changes also refer to main. There was no issue (at the moment) just using master, as it just seemed to work. But no one was using the latest version of git, which also apparently defaults to main.

@sstevens2
Copy link
Contributor

For the latest version of git, from what I've seen you still need to configure your default branch to be main with something like git config --global init.defaultBranch main.

I taught git last week and honestly I installed git with xcode on this computer and didn't want to try to figure out how to update before the lesson. So instead, I did git checkout -b main as a setup step after initializing the repo (and explained why) and since there were no commits on master it doesn't exist anymore. The only person in the class this didn't work for was someone who had git 1.XX version instead. So they had to commit first and then I had them switch branches and delete the master branch later.

cd planets
git init
git checkout -b main

Then your branch is named main and the master branch doesn't exist.

This also was a bit more relevant for me because I teach a custom version that teaches branches and PRs so we need to talk about branches anyway. I still presented it as a setup step and explained that master is a historical reference to slavery and as a community we are moving to the default branch being called main instead.

@chendaniely
Copy link
Contributor

If you do forget to change your branch names and master is already been commited to. you can use git branch -m main which will rename the current branch you are on. or more explititly renaming master to main via git branch -m master main.

this should reduce the git-mastrics of creating and deleting branches in separate steps (which tbh is what I normally do)

reference: https://stackoverflow.com/questions/6591213/how-do-i-rename-a-local-git-branch

@zkamvar
Copy link
Contributor

zkamvar commented Oct 28, 2020

FWIW, the new version of the git installer for windows now gives the users an option to explictly switch their default branch to 'main': carpentries/workshop-template#711

@sstevens2
Copy link
Contributor

Should we add a step to change the branch to main after git init for the folks who are on mac/linux systems? I can draft a PR tomorrow for review if so.

@ha0ye
Copy link

ha0ye commented Jan 6, 2021

Seconding @sstevens2's suggestion to add these instructions to the config step.

@srerickson
Copy link

srerickson commented Feb 19, 2021

In addition to adding instructions for changing the branch from master to main after git init + first commit, as suggested by @sstevens2, I think it makes sense to add a section to the setup episode. Something like this:

> ## Default Branch Name
> 
> Source file changes are associated with a "branch." By default, Git will create a branch called `master` 
> when you create a new repository with `git init` (as explained in the next Episode). This term evokes 
> the racist practice of human slavery and the software development community has moved to adopt 
> more inclusive language. Notably, new repositories created through GitHub use `main` as the default
> branch name.
>
> With Git versions 2.28 and higher, you can set a different name for the initial branch. To set main as 
> the default branch name do:
>
> ~~~
> $ git config --global init.defaultBranch main
> ~~~
> {: .language-bash}

@ha0ye
Copy link

ha0ye commented Feb 23, 2021

As of now, the binary version for Mac from the Git website is only on 2.27.0, and the version from Apple via xcode install is 2.24.3 (on my machine anyway). It might be good to include additional changes to check the initial branch when creating a new repo as part of the lesson, so that instructors are not left dealing with different branch names across installs and versions. (I don't think asking mac users to install via homebrew or source is a good idea.)

@zkamvar
Copy link
Contributor

zkamvar commented Mar 17, 2021

As of yesterday, the mac binary has been built for version 2.31.0: https://git-scm.com/download/mac, so these features will now be default for new installations.

@lorraine-heilman
Copy link

Hello All,
more info on how this played out this week at the NOAA Carpentries workshop: https://annajiat.github.io/2021-05-10-noaa-online/ where I was a helper.

The latest pc windows version of git bash (2.31) allows the user to choose their own default branch name on install. Previous versions default to "master". This resulted in a class where some people had master and a few had main in their git repositories and there is a possibility that someone will have some other name in the future. We hadn't taken the time to do the following:
cd planets
git init
git checkout -b main
as Sarah recommended above and there was a small amount of confusion in episodes 7 and 8. I think that because for the time being, the default behavior of git-bash depends on the participants version and probably will for a while before everything is switched over to "main", that it should be addressed in episode 3 and all subsequent episodes. I found Paul's pull request for changing all the master to main that Sarah mentioned above , but haven't found one for updating episode 3 to reflect the changes above. Does this still need to be done? I can take a crack at it if so.
Cheers
Lorraine

sstevens2 added a commit to sstevens2/git-novice that referenced this issue May 17, 2021
@kekoziar
Copy link
Contributor

kekoziar commented Jul 5, 2021

Implemented in e06701b

@kekoziar kekoziar closed this as completed Jul 5, 2021
zkamvar pushed a commit that referenced this issue May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants