how to push my project to github in a default branch, or merge two github branches remotely?

Advertisements

I created an editor project by angular, I want to push it in githup, I followed the following steps (I executed the following git commands):

git init
git add .
git commit -m "push editor project"

all this in branch local master.
I create a github account.
I create an "editorangular" repository in branch main.
I executed the commands:

git remote add origin master git@github.com:najib132/editorangular.git
git remote -v

(it gives me two links:

origin git@github.com:najib132/editorangular.git (fetch)
origin git@github.com:najib132/editorangular.git (push)

)
when i executed command

git push -u origin main

it gives me error:

$ git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'github.com:najib132/editorangular.git'

then I execute command: git push -u origin master
it creates a remote branch master.
in github branch main it not from my project, and when i change branch to master i find my project.
so I want to merge between these two remote branchs master and main, or push my project directly to the default branch main

>Solution :

You have two options:

  • Merge locally and push
  • Pull request on the remote

Option 1: Merge locally and Push

on your command line while on the master branch, you can do the following commands:

git checkout main

if that fails saying the main branch doesn’t exist or something, just add the -b switch

git checkout -b main

then push it up

git push -u origin main

At this point your code will be on the main branch, and on the master branch. You might want to delete your master branch. You have to delete it on both the remote and locally.

To delete the branch on the remote, issue the following command:

git push origin :master

Note the colon (:) before the branch name

To delete the branch locally, issue the following command while on some branch other than the one you are trying to delete

git branch -d master

you might get a warning about it not being synced to the remote, it suggests capitalizing the -D switch to force it. go ahead and do this if that is the case.

Option 2: Create a pull request on the remote.

Follow the instructions on this page – https://github.com/najib132/editorangular/compare/main…master

How to get there:
Select the "Pull Requests" menu option at the top and click the green "New Pull Request" button

Then select which branch you are merging from and into before clicking "Create pull request"

You will have the opportunity to add any additional details you would like here.

Scroll down to the bottom to finalize the merge

and complete it.

Bonus Option: Make master your default branch

Visit the settings for the repository and under the "Branches" menu you can select the default branch. That page can be directly accessed by you at this link – https://github.com/najib132/editorangular/settings/branches

Note: You may still want to clean up your main branch by deleting it both on the remote and locally.

Leave a ReplyCancel reply