
Creating a new Git Repository: Master/Main issues
I had a local git repo that I needed to connect and push to a new remote repo. First, I created the new remote repo via the web interface and initialized it with a license file. Then I came back to my existing local repo, that was newly created as well with "git init", and issued the following commands: ~$ git remote add origin https://github.com/ erikamart/myrepo.git ~$ git branch -M main ~$ git push -u origin main The last push command caused the error that said there were remote changes (i.e. the new remotely made license file) that needed to be fetched and merged in first. OK, so I did--> ~$ git pull origin main Unbeknownst to me, this automatically created a new branch called "main" to pull in the remote changes while still keeping my local branch that was defaulted to be called "master". So when I tried to "git push" again, it sent 2 branches called "main" & "master" to the remote repo. In the remote web interface I was forced to complete a pull request to merge the "master" into the "main" branch and then I deleted the "master" branch since it was no longer needed. Then on my local repo, every time I tried to "git pull" to merge the changes made in the web interface, I would get the error: "Your configuration specifies to merge with the ref 'refs/heads/master' from the remote, but no such ref was fetched." This meant that even though I deleted the "master" branch, I did not locally delete the "remote-tracking branch" and reset the upstream tracking information off the now gone "master" branch. The solution ended up being to use the following commands to fix it: 1. View just remote-tracking branches --> ~$ git branch -remote >> origin/main 2. Check the local repo status and reset the tracking info --> ~$ git status ~$ git branch --unset-upstream ~$ git branch --set-upstream-to=origin/main 3. Remove obsolete local remote-tracking branches for remote branches that no longer exist --> ~$ git fetch origin --prune