

Names commonly chosen instead of 'master' are 'main', 'trunk' and Of your new repositories, which will suppress this warning, call: To configure the initial branch name to use in all When you say simply git init, you’ll see a message like this one: Using 'master' as the name for the initial branch. Indeed, if you have not configured that setting, recent versions of Git will prompt you to do so. You can set the default branch name for all repositories that you create with git init, so that somename is the default initial branch name. In addition, by saying: git config -global -add faultBranch somename To set the default initial branch name for this repository to somename. When you say git init to start a repository, you can say: git init -b somename There are actually two ways to change it. In recent versions of Git, you are given the ability to change that behavior. As a result, when you do make your first commit, the branch name pointing to it is master. But that branch has a name! Where did that name come from? Well, under the hood, a newly created Git repository has its HEAD configured to point to refs/heads/master - even though there is no actual master branch yet, because you haven’t yet made your first commit. At that point, a branch is created for you.

You don’t actually have a branch until you have some files and you first say git add and git commit.

A branch, after all, is just a name for a commit but a newly created Git repository has no commits. Okay, that’s not completely accurate, because when you first create a local Git repository, it appears to have no branches at all. What’s in a name?īy default, as a long-standing convention, when you first create a local Git repository by saying git init on your computer, the new repository has a single branch called master. That change has to do with the default name of the very first branch in your repository.
#Commit and push to a different branch not master git how to
Why is this worth discussing? It’s because, lately, there has been a lot of confusion about how to do it - thanks to a change that GitHub made, starting in October of 2020. That’s the situation that this article is about. Suppose you want to create both a GitHub repository and a local repository, and pair them and keep them synchronized. That makes a local copy, and now you’re immediately ready to start working on the local copy.īut suppose there is no GitHub repository to start with. You tell your local Git to clone that repository onto your local computer. Well, it’s easy if you are starting with a situation where the repo you want to use is already stored on GitHub. So you are likely to want a Git repository to live both on your computer and at GitHub. This is good for tasks such as backup (keeping a copy of your work offsite, in case something happens to your computer) and collaboration (because multiple people might be allowed to copy the same remote repository onto their computer and work on it).Ī common place to keep the remote copy of a Git repository is GitHub. One of Git’s most important features is its ability to synchronize between two copies of a repository living in two different places - typically, a local copy living on your computer, and a remote copy living somewhere off on the Internet. (You might want to read the earlier post first, before reading this one, so that we’re sharing the same conceptions of what Git is and how it works.) That syncing feeling This change, judging by the number of posts and questions about it online, seems to worry a lot of users but as we shall see, it’s really not a big deal at all. It’s the story of a change in the policies, at GitHub and within Git itself, about what the default initial branch name should be. Today’s article is about the branch names master and main. Following on from my earlier blog post on understanding (and misunderstanding) Git, let’s dive deeper into some individual Git topics.
