I created a new repository in Github and I need to:
- Create new local repository
- Rename de master branch to main
- Create a new branch named develop
- Add all files to branch develop
- Merge main from work so both branches are equal
- Push everything to GitHub.
Does it make sense? So I tried:
git init
git branch -m main
git remote add origin https://github.com/.../Project.git
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?
CodePudding user response:
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