Git commands are a leading cause of hair loss for many beginner software engineers, and even for some more experienced ones as well. I've finally realized something that might've helped me when I was first starting out and hopefully will save you some headaches too.
At some point in our development career we get real familiar with the classic
git push origin master*. What is this command actually saying though? "git push" is pretty clear, but what exactly is "origin master"? For the longest time I thought it meant:
push from your computer to GitHub
I thought origin was my computer, and master was GitHub. To my brain, origin was where the new code I wanted to push had originated (my computer, because that's where I wrote it) and master was where I wanted it to go. Not so far fetched. I was right that they are two separate entities, but I was wrong about which two entities.
Actually, origin refers to the repository on GitHub (aka the "remote repository") where you originally cloned your code from, and master is the branch in origin that you want to push your changes to. They both refer to what's on GitHub.
This cleared up so much for me. Suddenly, in a cascade of insight, other git commands started to make more sense too. It does get more complicated, but hopefully this simple shift in understanding is a stepping stone that will help you have a breakthrough of your own on your way to becoming a git ninja.
*Note: GitHub has changed "master" to "main" so, increasingly, the command will be
git push origin main. Older repos will sometimes still use "master". Good to be aware of both.