DEV Community

Discussion on: Git for Developers: Common Errors and How to Resolve Them 💻🔍

Collapse
 
abdelrahmanallam profile image
Abdelrahman Mohamed Allam

Hi @villelmo,

It seems like you're trying to push changes to a branch named "main" that does not exist in your local git repository or in the remote repository.

list your remote branches

git branch -a
Enter fullscreen mode Exit fullscreen mode

if you find the repo try

git push origin HEAD:main
Enter fullscreen mode Exit fullscreen mode

This will push your changes to the default branch named "main" in the remote repository.

If there is no branch main, then need to create it,

git checkout -b main
Enter fullscreen mode Exit fullscreen mode

Then add and commit, following with push

git add .
git commit -m "commit message"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
villelmo profile image
William Torrez • Edited
git checkout main
Enter fullscreen mode Exit fullscreen mode

fatal: A branch named 'main' already exists.

Get the same problem

git push origin master:master main:main
Enter fullscreen mode Exit fullscreen mode

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Collapse
 
villelmo profile image
William Torrez
 main
* master
  remotes/pb/main
  remotes/pb/master

Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
abdelrahmanallam profile image
Abdelrahman Mohamed Allam

it should go something like this

git push origin master:master main:main
Enter fullscreen mode Exit fullscreen mode