Merge Branches and Push


I created a new repository in Github and I need to:

  1. Create new local repository
  2. Rename de master branch to main
  3. Create a new branch named develop
  4. Add all files to branch develop
  5. Merge main from work so both branches are equal
  6. Push everything to GitHub.

Does it make sense? So I tried:

git init
git branch -m main
git remote add origin
git checkout -b work
git add .
git commit -m "Initial Commit"
git checkout main
git merge work
git push -u origin main

I get the error:

error: pathspec 'main' did not match any file(s) known to git

When running

git checkout main

Is there a better way to do what I am trying to do?


Without a commit, git won’t save the main branch. Following your instructions exactly, there will only be a work branch, so it makes sense you have failed on

git checkout main

Commit something to the main branch right after renaming it and you should be fine. Make sure you actually have some files in that directory or else you will commit nothing and it won’t save your branch.

This also then requires that you edit or add something after you switch to the work branch if you want the subsequent merge to actually do anything

Answered By – Ben Borchard

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published