I am a freshman computer science major trying to learn the basics of Git and GitHub using this very helpful video tutorial: https://www.udemy.com/course/git-expert-4-hours/. But, after listening to the videos about pushing and pulling, I'm confused as to what the correct commands are, since the teacher in the video uses "master" as the branch name, but my primary branch is called "main." (I think I read somewhere that "master" was renamed "main," which could explain my issue because the video tutorial was filmed in 2018.) Below, I detailed the different git commands I tried and their results. Does anyone know why some worked and some didn't and which ones I should be using to push and pull? Thank you so much!
For pulling, the teacher used git pull origin master
, which I replaced with git pull origin main
and I was able to successfully pull the code from my remote repository to my local repository.
However, for pushing, the teacher used git push -u origin master
. When I typed this exact command, I think I might have accidentally tried to merge two branches - I'm not exactly sure what happened. I also tried git push -u origin main
and git push origin main
, both of which resulted in error: src refspec main does not match any
. I finally was able to push the code from my local to remote repository using git push origin HEAD:main
, but even when I used the -u
flag, Git did not "remember" the branch I was trying to push to, so I was not able to use the shorter git push
and git pull
commands in the future, and I had to retype the whole longer command.
However, when I created a new branch called "err01," I was able to successfully push to that branch using git push origin err01
.
Does anyone know why some of these commands worked and some didn't and which ones I should be using to push and pull? Thank you so much!