I tried to upload my code to a repository on GitHub.
These are the commands I used:
git add .
git commit -m "text"
git push
However, instead of uploading the code to the main
branch on GitHub, it created a master
branch on my repository.
It looks like this now, with "main" shown first, then "master":
May I ask how can I merge these two branches?
CodePudding user response:
You can merge these two branches with:
git switch <branch you want to merge to>
git merge <branch you want to merge onto the current branch>
git branch -d <branch name> //Optional, will delete the branch
To avoid this issue with future repositories, you can run this command:
git config --global init.defaultBranch main
It tells git to name the default branch 'main' instead of 'master' when using 'git init'.
For further information on branches take a look at this: Github - Manage branches
CodePudding user response:
This is effectively a duplicate of How to merge main and master branches? My answer there, however, is much longer and more general: it covers your specific case, but your specific case is quite simple as you have nothing interesting on your GitHub main
. You can just replace your existing GitHub main
with what you currently call master
, using:
git branch -m main
git push --force origin main
from your computer (your laptop). Normally, git push --force
(or even git push --force-with-lease
) is something to use carefully at best. Here, you're using it carefully—though you may not yet know it.