Github
Copy from Gitlab to Github
2
I want to change my master branch to main branch
Changing the default branch name from "master" to "main" in Git can be significant for adopting more inclusive terminology. Here’s how you can do this both locally and on remote repositories such as GitHub, GitLab, or Bitbucket.
Locally Changing the Branch Name
Rename the Branch Locally Open your terminal and navigate to your Git repository. Use the following command to rename the branch:
This command changes the branch name from
master
tomain
.Push the New Branch to Remote Push the newly named branch to your remote repository:
This command pushes the
main
branch to your remote repository (origin
) and sets it to track the remote branch.
Remotely Changing the Default Branch
Changing the branch name locally is only part of the process. You also need to update the default branch on your remote repository.
GitHub
Go to your repository on GitHub.
Click on "Settings."
Navigate to "Branches" on the left sidebar.
In the "Default branch" section, click the switch button next to the current default branch.
Select
main
from the dropdown list.Confirm the change if necessary.
GitLab
Go to your project in GitLab.
Click on "Repository" and then "Branches."
Click on the "Default branch" button.
Change the default branch to
main
.Save the changes.
Bitbucket
Navigate to your repository in Bitbucket.
Click on "Repository settings."
Under "Repository details," find the "Main branch" and select
main
.Save your changes.
Clean Up
After changing the default branch, you might want to remove the old master
branch from the remote:
This command deletes the master
branch from the remote repository.
Update Local Clones
If you or others have local clones of the repository, you should switch to the new main
branch in those clones:
Make sure to update the local configurations and reset the upstream tracking branch:
Summary
Changing the branch name from master
to main
involves renaming the branch both locally and remotely, then setting the new branch as the default in your Git hosting service. This change is part of a broader effort within the tech community to adopt more inclusive language. Always ensure to communicate these changes with your team or collaborators to avoid confusion and workflow interruptions.
when I do git push it is trying to push it to upstream. I need to change it to only origin
It sounds like the default remote for your current branch has been set to upstream
instead of origin
. You can change this default remote setting using the git
command.
Here's how you can change the default remote (the "upstream" in Git terminology, not to be confused with a remote named "upstream") for your current branch to origin
:
Check Current Upstream: First, verify the current upstream (default remote) for your branch with:
This command shows you the upstream configured for each branch.
Change the Upstream Remote: If the current branch is set to push to
upstream
, change it toorigin
using:Replace
<branch>
with your current branch name.Push to Origin: After setting the upstream to
origin
, you can push using:Now, it should push to
origin
by default for your current branch.
If you want to push just once to origin
without changing the default setting, you can also explicitly specify the remote when pushing:
Make sure to replace <branch>
with the name of your branch. This command will push your branch to the origin
remote just for this operation, without changing the default remote setting.
Last updated
Was this helpful?