'Can't push to main on new git repo
I am realtivly new to git and have created a new github repo after the update which switched master to main.
The first problem I had was that when I pulled git pull origin main nothing came down. At the time the repo continued a .gitignore, readme, and a licence. I solved this by manually downloading them.
However, I am unable to push to main. When I tried to run git push origin main I got an error message and was told by git to run the following: git push --set-upstream origin master. After running that, I can now push to master but not main. When I try to run git push origin main I get the following error:
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/Ebony-Ayers/CS-style-text-format'
How can I make it so that I can push to main rather than master as according to the repo on the github website main is my default branch? Any help would be greatly appreciated.
Solution 1:[1]
When you want to push your local repo to remote in GitHub but your local repo branch is named 'master' and your remote is named 'main' you wont be able to push.
The solution as described by GitHub documentation is to rename your local repo to 'main'.
To do this your current branch needs to 'master'
Verify your branch using command :
git branch
this will list all branches and highlight your current branch.
Then to rename the branch the command is :
git branch -M main
The flag -M is a shortcut for flags : --move --force.
The move means move/rename a branch, together with its config and reflog.
Additionally, as commented by (#Sal from Dec 24, 2020 at 8:20) for convenience you can set 'main' as the default branch with:
git push --set-upstream origin main
Once 'main' is default then you can just do git push or git pull without adding the branch name to the command.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yariv |
