-2

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!

Anna
  • 1
  • 1
    They should be the same except every instance of `master` should now be `main`. Are you sure that the branch on origin is called `main`? – evolutionxbox Jan 04 '21 at 20:04
  • @evolutionxbox Yes, I think so. The branch that was automatically created is called ```main```. What do you mean by the "branch on origin"? Sorry for my confusion, I'm very new at this. – Anna Jan 04 '21 at 20:08
  • 1
    origin is the name of the default "remote" repo (a git repo on another computer) - So "branch on origin" means, does that branch name exist inside that repo on the other computer. Normally you can see these by using `git branch -r` – evolutionxbox Jan 04 '21 at 20:23
  • Ok thank you! Yes, when I type ```git branch -r```, it lists ```origin/main```. – Anna Jan 04 '21 at 20:26
  • 1
    Does this answer your question? [git push error: src refspec main does not match any on linux](https://stackoverflow.com/questions/65173291/git-push-error-src-refspec-main-does-not-match-any-on-linux) – evolutionxbox Jan 04 '21 at 20:33
  • Thank you! That other question did relate to mine and was very helpful! – Anna Jan 05 '21 at 00:29

1 Answers1

1

You may checkout to the "main" branch and do pull or push directly from there

Appu Rajendran
  • 192
  • 1
  • 2
  • 10
  • 1
    Yes I think that was the issue! It seems to work when I checkout into the "main" branch. Thanks so much! – Anna Jan 05 '21 at 00:26