P
Pulse Beacon

How do I change the default branch in GitHub

Author

Henry Morales

Published Apr 19, 2026

On GitHub.com, navigate to the main page of the repository.Under your repository name, click Settings.In the left menu, click Branches.Under “Default branch”, to the right of the default branch name, click .Use the drop-down, then click a branch name.Click Update.

How do I change my main branch?

  1. $ git branch –move master main.
  2. $ git push –set-upstream origin main.
  3. git branch –all * main remotes/origin/HEAD -> origin/master remotes/origin/main remotes/origin/master.
  4. $ git push origin –delete master.

Which GitHub branch is default?

Unless you specify a different branch, the default branch in a repository is the base branch for new pull requests and code commits. By default, GitHub names the default branch main in any new repository.

How do I change my default master branch?

Select your Git repository. Your branches are displayed under your repo. Select the … next to the branch you want to set as default, then select Set as default branch.

How do I change the branch in Git?

  1. The easiest way to switch branch on Git is to use the “git checkout” command and specify the name of the branch you want to switch to.
  2. A quick way of switching branch on Git is to use the “git switch” command and specify the name of the branch you want to switch to.

How do I change my main branch to master in GitHub?

  1. Change the branch name. git branch -m master default. …
  2. Set remote upstream tracking for the new branch. git push -u origin default. …
  3. Fetch all the branches. git fetch. …
  4. Update the upstream remote HEAD. git remote set-head origin -a. …
  5. Rename the default branch. git branch -m master default.

How do I go from branch to master?

  1. git stash or git commit -m “XXX”
  2. git checkout master.
  3. git branch -D merchantApi.

What is the difference between main and master branch?

By default, GitHub uses the term “master” for the primary version of a source code repository. … 1, 2020, any new repositories you create will use main as the default branch, instead of master,” the company said. Existing repositories that have “master” set as the default branch will be left as is.

How do I change the default branch in CodeCommit?

  1. In Repositories, choose the name of the repository where you want to change settings.
  2. In the navigation pane, choose Settings.
  3. In Default branch, choose the branch drop-down list and choose a different branch. Choose Save. Tip.
How do I remove a branch from GitHub?
  1. On GitHub.com, navigate to the main page of the repository.
  2. Above the list of files, click NUMBER branches.
  3. Scroll to the branch that you want to delete, then click .
Article first time published on

How do I delete a remote master branch?

Deleting remote branches To delete a remote branch, you can’t use the git branch command. Instead, use the git push command with –delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .

How do I create a new branch in GitHub?

  1. At the top of the app, click Current Branch and then in the list of branches, click the branch that you want to base your new branch on.
  2. Click New Branch.
  3. Under Name, type the name of the new branch.
  4. Use the drop-down to choose a base branch for your new branch.
  5. Click Create Branch.

How do I create a new branch?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

How do I push to main branch GitHub?

  1. Step 1 – Move the ‘master’ branch to ‘main’ Run the following command which creates a branch called ‘main’ using the history from ‘master’. …
  2. Step 2 – Push ‘main’ to remote repo. …
  3. Step 3 – Point HEAD to ‘main’ branch. …
  4. Step 4 – Change default branch to ‘main’ on GitHub site. …
  5. Step 5 – Delete ‘master’ branch on the remote repo.

How do I reset my head?

To hard reset files to HEAD on Git, use the “git reset” command with the “–hard” option and specify the HEAD. The purpose of the “git reset” command is to move the current HEAD to the commit specified (in this case, the HEAD itself, one commit before HEAD and so on).

How do I revert to git master?

When you want to revert to a past commit using git reset – – hard, add <SOME-COMMIT>. Then Git will: Make your present branch (typically master) back to point at <SOME-COMMIT>. Then it will make the files in the working tree and the index (“staging area”) the same as the versions committed in <SOME-COMMIT>.

What is Git branch Main?

The default branch name in Git is master . As you start making commits, you’re given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically. The “master” branch in Git is not a special branch.

Can we rename a git branch?

The git branch command lets you rename a branch. To rename a branch, run git branch -m <old> <new>. “old” is the name of the branch you want to rename and “new” is the new name for the branch.

How do I merge branches in CodeCommit?

  1. To merge two branches using the fast-forward merge strategy, run the merge-branches-by-fast-forward command.
  2. To merge two branches using the squash merge strategy, run the merge-branches-by-squash command.

Why did GitHub switch from master to Main?

GitHub took action based on the Conservancy’s suggestion and moved away from the term master when a Git repository is initialized, “We support and encourage projects to switch to branch names that are meaningful and inclusive, and we’ll be adding features to Git to make it even easier to use a different default for new …

How do I move a file from master to Main in GitHub?

  1. Step 1 – Move the ‘master’ branch to ‘main’ Run the following command which creates a branch called ‘main’ using the history from ‘master’. …
  2. Step 2 – Push ‘main’ to remote repo. …
  3. Step 3 – Point HEAD to ‘main’ branch. …
  4. Step 4 – Change default branch to ‘main’ on GitHub site. …
  5. Step 5 – Delete ‘master’ branch on the remote repo.

How do I merge two GitHub branches?

  1. In GitHub Desktop, click Current Branch.
  2. Click Choose a branch to merge into BRANCH.
  3. Click the branch you want to merge into the current branch, then click Merge BRANCH into BRANCH. …
  4. Click Push origin to push your local changes to the remote repository.

Can we delete main branch in GitHub?

The GitHub.com browser interface allows you to delete (and create) remote branches. … On the branches overview page, you can then choose a branch to delete: However, it’s very important to understand that you can only delete remote branches, not any of the branches in your local Git repository!

Is it possible to delete master branch in git?

gitlab has set that the master branch as default and protected, which means you can not just remove it from your local machine. You first need to remove the protection and set main as your new default. … Now you are able to delete the master branch.

How do I remove a branch from GitHub terminal?

Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn’t been pushed or merged yet. The branch is now deleted locally.

How do I create a new push and branch?

  1. Create branch using command prompt. $git checkout -b new_branch_name.
  2. Push the branch. $git push origin new_branch_name.
  3. Switch to new branch it will already switched to new_branch_name otherwise you can use.

How do I push a local branch to a different branch?

Push Branch to Another Branch In some cases, you may want to push your changes to another branch on the remote repository. In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.