I created a new repo on GitHub and cloned it to a folder on my desktop using SSH. Then, I created a README.md file, edited and saved. Afterwards, I used git to stage my changes and commit a snapshot. After writing my commit message, I received the following message:
On branch main
Your branch is based on 'origin/main', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working tree clean
This message only occurs when I create an empty repo, clone it, and attempt to make git commits. By initializing a different repo with a README.md file using the new repo form on GitHub, I was able to prevent this message from coming up when making commits to that repo. So, problem solved – mostly.
I wanted to create a README.md file on my own machine, and push the changes to my repo myself. I expected to go through the git workflow without any issues. When I got the message I researched it on Stack Overflow and found some other cases of people receiving the same message, but their cases weren’t quite like mine. In most cases, people removed their main branch – but I haven’t removed anything. I simply created a brand new empty repo and attempted to make changes.
So, why did this happen?
Leland is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Without a file, you can’t commit. Without a commit, you can’t create a branch. There can’t be a main
branch in the remote repository, if the repository is empty and there are no files.
You’ve created files in your local repository, committed them and created a main
branch, but the main
branch doesn’t exist in the remote repository.
The message
Your branch is based on ‘origin/main’, but the upstream is gone.
is confusing, but the authors probably didn’t have this special situation in mind when they wrote this message.
You can verify it yourself. Go to your repository on GitHub. You should the view for empty, initial repositories with “Quick setup” steps. You won’t find any branches in the repository.
When you create a new remote repository and initialize it with files like README.md, GitHub will create the first commit and a main
branch for.