Hey friends! So I’m learning the basics of GitHub and git bash through a YouTube video
I’m at 28:30 in the video and we’ve gone to the GitHub website and created the repository for the files we want to move from our machine.
I first used the command
$ git remote add origin https://github.com/spabsa/Kane-Concrete-Construction.git
then did
git push -u origin master
After this a login appears to enter my info, which i did correctly. And according to the video thats the last step. Then you should be able to reload the GitHub page and see the files in the repository. Except I Got an error message in my git bash that says
Seth@DESKTOP-05S62SG MINGW64 ~/Desktop/PortfolioProjects/Kane Concrete and Construction (master)
$ git push -u origin master
To https://github.com/spabsa/Kane-Concrete-Construction.git
! [rejected] master → master (fetch first)
error: failed to push some refs to ‘https://github.com/spabsa/Kane-Concrete-Construction.git’
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.
And then I got an email from github talking about personal access tokens?? If i could get a step by step guide on how to fix this I’d really appreciate it. I’m really confused:(
The error means that there are some commits on GitHub that you don’t have locally. When that happens the remote (in this case GitHub) refuses the push, because it’s not able to solve any conflicts while merging your commits and the commits already there.
It seems that you’ve added a README while creating the repository.
The fix is not that hard, instead of pushing, you first need to pull (git pull) so that everything that is on GitHub is also available locally, and then you can push (git push).
I had a similar problem, maybe the same. Certainly your explanation is very helpful. The error message cannot tell us everything but it would probably would have helped me if it said how to determine what is relevant, such as the README. I know from experience that it is not as easy to learn Git and GitHub as we want it to be.
everything is relevant. Git doesnt care what the changes are; it simply looks at the signature of the repository - the hex value of the HEAD commit number, and says “It’s not the same as the last one you pulled. The repository is not the same as the local base copy, abort.”
I was trying to be non-confrontational so I did not reply to you. Since you replied to me, I am saying that it would help to be able to get the same answer from Git that rpkamp provided here. As indicated here, Git does care about the changes that affect the signature of the repository. I get the impression that Git is easy to understand, that it is simply a matter of reading the documentation. I know that there are many people that will disagree. So go ahead and say what you want to say, just don’t assume I agree if I do not respond.
Well, clearly you’ve got a problem with me, dunno what that’s about but whatever. Feel free not to respond.
The signature of the repository is affected by every change. So… yeah, you’re correct. As am I.
So what you’ve done is create a repo in Github and made a commit to it (adding the readme), which starts a chain of history.
Then you git init’d locally, which starts another chain of history.
You’ve then told git to pull the remote changes in, but it can’t figure out what changes you need, because your local version of history doesnt intersect the remote one at any point - that is to say, you’ve got two completely unrelated repositories, so the git client refuses to merge them because it doesn’t have an understanding of how.
Basically you’ve told it to add your orange collection to your apple collection.
Simplest thing at this point is to save your changed files out to a different directory (or rename the one you’re working in), git clone your github repository down to your local system, so that your local system is using the github repository’s base history, move your changed files into the new local repo folder, and form a commit against the newly cloned history.
I can see both sides of the issue of using the documentation. I have responded to many thousands of questions in other forums so I understand extremely well the advice to look at the documentation. I also have experienced the frustration of trying to use the Git documentation to figure out what to do.
Have you tried the Git - Book? Probably you have and if so then I assume it did not help. I created What is a repository where I said the book is not helpful (you can see the actual comments there) and the answer was that I should improve it. I intend to improve it when I know enough to do it. I have not found anything that I can recommend. However the following are some links I have gathered and maybe they will help you.
That last one uses styles I saw quite often when I edited articles written by people in India; they are more likely to use questions for titles, such as How to install? instead of Installation.