Reputation: 77
I have a master branch and a main branch in git-hub. This was not intentional I realized that I have been pushing with master so everything went to master branch. However git-hub is now using main instead of master as first position. How can I move my master branch into main branch?
Upvotes: 6
Views: 7239
Reputation: 188
Set local master to track remote main:
git branch --set-upstream-to origin/main master
For first pull it will show error refusing to merge unrelated histories
so you can pull with git pull origin main --allow-unrelated-histories
Upvotes: 0
Reputation: 1840
There are multipe ways to achieve this, but with pure git it can be done as follows:
#Change to the main branch
git checkout main
#Rebase the main branch on top of the current master. In easy words, go to the last point the two branches have in common, then add all the changes master did in the meanwhile and then add the changes done to main. If main is empty this is equivalent to
# git checkout master; git branch -D main; git checkout -b main
#which deletes the current main and then copies master over to main
git rebase master
# push back to GitHub (--force, because rabse does not add a commit, but changes the status, so push will be rejected without it)
git push --force
Upvotes: 4
Reputation: 1403
You can delete or rename a branch through the github web interface by visiting
https://github.com/YourName/YourRepo/branches
At time of writing you can access that page from the front page of your repository through the branches
link:
And you can click the writing implement buttons to rename their associated branch:
It is worth noting that deleting and renaming branches through github is just as potentially destructive as doing it with CLI git or a GUI git client. You can of course re-push branches from your local clone, but you should make sure that clone is up to date before proceeding if you feel unsure.
Upvotes: 5
Reputation: 1
Create a PR from master to main in the GitHub Webinterface. If you want to do it local:
git checkout main
git merge master
git push
Upvotes: -2